Implement background clip functionality for bumpers
ci / build-backend (push) Successful in 2m14s
ci / build-frontend (push) Successful in 49s
ci / tests (push) Successful in 2m7s
ci / sonar (push) Successful in 7m39s

Enhanced the bumper system to support a new background type, 'Clip', allowing text to be overlaid on existing video clips. This update includes the addition of a BackgroundClipShowId property in various records and classes, ensuring that the clip's duration dictates the bumper length. Updated validation rules, mapping, and rendering logic to accommodate this new feature. Localization strings were also updated to reflect the new background option and its implications for audio handling.
This commit is contained in:
Leonid Pershin
2026-07-29 23:54:11 +03:00
parent 35cb4b09dc
commit 6be373476c
26 changed files with 1798 additions and 24 deletions
@@ -183,7 +183,16 @@ public sealed class FfmpegBumperRenderer(
// анимированный градиент.
var inputs = new List<string>();
string videoPrefix;
if (!string.IsNullOrEmpty(spec.BackgroundFile))
if (!string.IsNullOrEmpty(spec.ClipFile))
{
// Готовый ролик как подложка. Не зацикливаем: длину задаёт он сам, а выравнивание по
// сегменту добираем стоп-кадром — повтор первых секунд в конце заметнее любой заморозки.
inputs.AddRange(["-i", spec.ClipFile]);
videoPrefix =
$"[0:v]scale={w}:{h}:force_original_aspect_ratio=increase,crop={w}:{h}"
+ $",tpad=stop_mode=clone:stop_duration={Fmt(target)},fps=30,format=yuv420p";
}
else if (!string.IsNullOrEmpty(spec.BackgroundFile))
{
if (IsImage(spec.BackgroundFile))
inputs.AddRange(["-loop", "1"]);
@@ -212,8 +221,17 @@ public sealed class FfmpegBumperRenderer(
}
// Вход 1 — звук: загруженная музыка (петля + loudnorm) либо синтезированный джингл.
// У ролика-подложки без джингла звучит его собственная дорожка — второго входа не нужно.
string audioChain;
if (!string.IsNullOrEmpty(spec.MusicFile))
if (spec.UseClipAudio)
{
audioChain =
$"[0:a]loudnorm=I={_media.LoudnessTargetLufs.ToString(CultureInfo.InvariantCulture)}:TP=-1.5:LRA=11"
// apad добивает тишиной хвост, дорисованный стоп-кадром: без него поток звука
// кончается раньше видео и ffmpeg обрезает кадр по нему.
+ $",apad,afade=t=out:st={Fmt(outStart)}:d=1.0[a]";
}
else if (!string.IsNullOrEmpty(spec.MusicFile))
{
inputs.AddRange(["-stream_loop", "-1", "-i", spec.MusicFile]);
audioChain =
@@ -23,6 +23,12 @@ public sealed class FileSystemMediaStorage(MediaPathResolver paths) : IMediaStor
}
}
public string? ResolvePlaylistPath(Guid assetId)
{
var path = Path.Combine(paths.AssetDir(assetId), "index.m3u8");
return File.Exists(path) ? path : null;
}
public async Task<string> SaveUploadAsync(
Stream content,
string extension,
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,37 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace TeleWave.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class BumperClipBackground : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "BackgroundClipShowId",
table: "BumperTextVariants",
type: "uuid",
nullable: true
);
migrationBuilder.AddColumn<Guid>(
name: "BackgroundAssetId",
table: "BumperAssets",
type: "uuid",
nullable: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(name: "BackgroundClipShowId", table: "BumperTextVariants");
migrationBuilder.DropColumn(name: "BackgroundAssetId", table: "BumperAssets");
}
}
}
@@ -164,6 +164,9 @@ namespace TeleWave.Infrastructure.Migrations
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<Guid?>("BackgroundAssetId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
@@ -262,6 +265,9 @@ namespace TeleWave.Infrastructure.Migrations
b.Property<int>("Background")
.HasColumnType("integer");
b.Property<Guid?>("BackgroundClipShowId")
.HasColumnType("uuid");
b.Property<Guid>("BumperTemplateId")
.HasColumnType("uuid");