feat(review): High quality playback switch and per-version ProRes download
Deploy / deploy (push) Successful in 3m23s
Deploy / deploy (push) Successful in 3m23s
Worker 1.7.0 (preview.highQuality, default on) now, after the AE render: - encodes a High quality MP4 from the delivery MOV (full-res H.264 High, CRF 14 capped at 100 Mbps) -> Version.hqFileUrl - uploads the MOV itself -> Version.highResKey/Filename/Size Both best-effort (the preview never fails over them), with a lease keep-alive during the long encode/uploads; the export timeline records what was attached. Player: HQ switch when a High quality source exists; keeps frame, play state, speed and zoom, remembered per browser, falls back to Standard if the file won't load. ProRes itself stays download-only (browser support). Downloads: the client portal's High Res button serves the version's ProRes (client-code filename), falling back to the shot's manual file; staff get a ProRes button on the review page. Housekeeping (lib/render-pipeline/high-res.ts): HQ MP4 + ProRes are kept while a version is latest, client-shared, approved or younger than preview.highResRetentionDays (14); otherwise deleted from storage. Runs per task after finalize and hourly from the reaper; deleting a version or a reslate removes its files. The Standard MP4 is never touched. Also: ProRes/Handles top-bar buttons go icon-only below lg so they don't overlap the version selector. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -175,6 +175,11 @@ public sealed class PreviewManifest
|
||||
public string Mp4Output { get; set; } = "";
|
||||
public string? SlateScopeProp { get; set; }
|
||||
public string? SlateSubmissionProp { get; set; }
|
||||
/// <summary>
|
||||
/// Also encode the High quality MP4 from the MOV and upload the MOV itself
|
||||
/// as the version's High Res file (server "preview.highQuality").
|
||||
/// </summary>
|
||||
public bool HighQuality { get; set; }
|
||||
public SlateInfo Slate { get; set; } = new();
|
||||
|
||||
public int TotalFrames => FrameEnd - FrameStart + 1;
|
||||
|
||||
@@ -441,6 +441,32 @@ public sealed class JobExecutor
|
||||
job.Id, machineId, "thumbnail", result.ThumbnailPath, "image/jpeg", shutdown);
|
||||
}
|
||||
|
||||
// High quality MP4 + the MOV as the version's High Res download
|
||||
// (§9.6). Both optional: a failure here costs the extras, never the
|
||||
// preview, which is already safely uploaded.
|
||||
string? hqKey = null;
|
||||
string? highResKey = null;
|
||||
long? highResSize = null;
|
||||
if (manifest.HighQuality)
|
||||
{
|
||||
await using var keepAlive = new LeaseKeepAlive(_api, job.Id, machineId, TimeSpan.FromSeconds(60), shutdown);
|
||||
|
||||
var hqPath = await _preview.TryMakeHighQualityAsync(job.Id, result.MovPath!, result.Mp4Path!, shutdown);
|
||||
if (hqPath is not null)
|
||||
{
|
||||
hqKey = await _api.UploadArtifactAsync(job.Id, machineId, "preview", hqPath, "video/mp4", shutdown);
|
||||
if (hqKey is null) _log.LogWarning("High quality MP4 upload failed for job {JobId}", job.Id);
|
||||
}
|
||||
|
||||
if (result.MovPath is not null && File.Exists(result.MovPath))
|
||||
{
|
||||
highResSize = new FileInfo(result.MovPath).Length;
|
||||
highResKey = await _api.UploadArtifactAsync(
|
||||
job.Id, machineId, "highres", result.MovPath, "video/quicktime", shutdown);
|
||||
if (highResKey is null) _log.LogWarning("ProRes upload failed for job {JobId}", job.Id);
|
||||
}
|
||||
}
|
||||
|
||||
_spooler.Enqueue("finalize", job.Id, new Dictionary<string, object?>
|
||||
{
|
||||
["machineId"] = machineId,
|
||||
@@ -449,6 +475,10 @@ public sealed class JobExecutor
|
||||
["deliveryMovPath"] = manifest.MovOutput,
|
||||
["previewMovKey"] = previewKey,
|
||||
["thumbnailKey"] = thumbKey,
|
||||
["hqPreviewKey"] = hqKey,
|
||||
["highResKey"] = highResKey,
|
||||
["highResFileName"] = highResKey is null ? null : Path.GetFileName(result.MovPath),
|
||||
["highResSize"] = highResKey is null ? null : highResSize,
|
||||
},
|
||||
["renderStats"] = new Dictionary<string, object?>
|
||||
{
|
||||
@@ -494,6 +524,12 @@ public sealed class JobExecutor
|
||||
PreviewStage.TryDelete(Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_run.jsx"));
|
||||
PreviewStage.TryDelete(Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_thumb.jpg"));
|
||||
if (tempAep is not null) PreviewStage.TryDelete(tempAep);
|
||||
try
|
||||
{
|
||||
var hqDir = PreviewStage.HighQualityDir(jobId);
|
||||
if (Directory.Exists(hqDir)) Directory.Delete(hqDir, recursive: true);
|
||||
}
|
||||
catch { /* scratch only */ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
namespace VFXReviewWorker;
|
||||
|
||||
/// <summary>
|
||||
/// Renews a job's lease with progress reports while the worker does something
|
||||
/// long that reports nothing on its own — the High quality encode and the
|
||||
/// ProRes upload can each outlast a 300 s lease, and an expired lease lets the
|
||||
/// reaper hand the job to another machine mid-upload.
|
||||
/// </summary>
|
||||
internal sealed class LeaseKeepAlive : IAsyncDisposable
|
||||
{
|
||||
private readonly CancellationTokenSource _cts;
|
||||
private readonly Task _loop;
|
||||
|
||||
public LeaseKeepAlive(ApiClient api, string jobId, string machineId, TimeSpan interval, CancellationToken shutdown)
|
||||
{
|
||||
_cts = CancellationTokenSource.CreateLinkedTokenSource(shutdown);
|
||||
var token = _cts.Token;
|
||||
_loop = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(interval, token);
|
||||
// Best-effort by contract (ApiClient.ProgressAsync never throws
|
||||
// on transport errors); progress stays at 1.0 — the render is done.
|
||||
await api.ProgressAsync(jobId, machineId, 1.0, null, null, null, null, token);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// stopped
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
_cts.Cancel();
|
||||
try { await _loop; } catch { /* already reported */ }
|
||||
_cts.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -302,6 +302,107 @@ public sealed class PreviewStage
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Scratch folder for a job's High quality encode.</summary>
|
||||
internal static string HighQualityDir(string jobId) =>
|
||||
Path.Combine(WorkerOptions.ScratchDir, $"job_{jobId}_hq");
|
||||
|
||||
/// <summary>
|
||||
/// High quality review MP4 (§9.6): the delivery MOV re-encoded as
|
||||
/// full-resolution, high-bitrate H.264 High — the player's "High" quality.
|
||||
/// ProRes itself only plays in Safari on a Mac, so the MOV is offered as a
|
||||
/// download and this is what streams. Never fatal: without it the version
|
||||
/// simply has Standard quality only.
|
||||
/// </summary>
|
||||
public async Task<string?> TryMakeHighQualityAsync(
|
||||
string jobId, string movPath, string mp4Path, CancellationToken ct)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_options.FfmpegPath) || !File.Exists(_options.FfmpegPath))
|
||||
{
|
||||
_log.LogWarning("No High quality MP4 for job {JobId}: ffmpegPath is not set or missing.", jobId);
|
||||
return null;
|
||||
}
|
||||
if (!File.Exists(movPath))
|
||||
{
|
||||
_log.LogWarning("No High quality MP4 for job {JobId}: MOV not found at {Path}.", jobId, movPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
var dir = HighQualityDir(jobId);
|
||||
Directory.CreateDirectory(dir);
|
||||
// Named after the review MP4 so the stored object reads as its sibling.
|
||||
var outPath = Path.Combine(dir, Path.GetFileNameWithoutExtension(mp4Path) + "_HQ.mp4");
|
||||
TryDelete(outPath);
|
||||
|
||||
var args = new List<string>
|
||||
{
|
||||
"-y", "-i", movPath,
|
||||
"-map", "0:v:0", "-map", "0:a?",
|
||||
// Visually lossless for review, capped so a busy shot can't balloon
|
||||
// past what a good connection streams. yuv420p 8-bit High profile
|
||||
// is the combination every browser decodes.
|
||||
"-c:v", "libx264", "-profile:v", "high", "-preset", "medium", "-crf", "14",
|
||||
"-maxrate", "100M", "-bufsize", "200M", "-pix_fmt", "yuv420p",
|
||||
"-c:a", "aac", "-b:a", "256k",
|
||||
// Index at the front so the player can start before it's all loaded
|
||||
"-movflags", "+faststart",
|
||||
outPath,
|
||||
};
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = _options.FfmpegPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
foreach (var a in args) psi.ArgumentList.Add(a);
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
using var process = Process.Start(psi);
|
||||
if (process is null)
|
||||
{
|
||||
_log.LogWarning("Could not start ffmpeg for the High quality MP4 (job {JobId})", jobId);
|
||||
return null;
|
||||
}
|
||||
// Drain both pipes (see RunFfmpegThumbnailAsync — an unread pipe deadlocks ffmpeg).
|
||||
var stderrTask = process.StandardError.ReadToEndAsync();
|
||||
var stdoutTask = process.StandardOutput.ReadToEndAsync();
|
||||
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
timeout.CancelAfter(TimeSpan.FromMinutes(30));
|
||||
try
|
||||
{
|
||||
await process.WaitForExitAsync(timeout.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_log.LogWarning("High quality encode for job {JobId} timed out or was cancelled — killing ffmpeg", jobId);
|
||||
try { process.Kill(entireProcessTree: true); } catch { }
|
||||
TryDelete(outPath);
|
||||
return null;
|
||||
}
|
||||
var stderr = await stderrTask;
|
||||
await stdoutTask;
|
||||
|
||||
if (process.ExitCode == 0 && File.Exists(outPath) && new FileInfo(outPath).Length > 0)
|
||||
{
|
||||
_log.LogInformation("High quality MP4 for job {JobId} encoded in {Sec:F0}s ({MB:F0} MB)",
|
||||
jobId, sw.Elapsed.TotalSeconds, new FileInfo(outPath).Length / 1e6);
|
||||
return outPath;
|
||||
}
|
||||
_log.LogWarning("High quality encode failed for job {JobId} (exit {Exit}): {Stderr}",
|
||||
jobId, process.ExitCode, Tail(stderr, 1200));
|
||||
TryDelete(outPath);
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogWarning(ex, "High quality encode failed for job {JobId} (non-fatal)", jobId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>How one ffmpeg attempt ended.</summary>
|
||||
private enum ThumbAttempt
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
every change that gets published. publish.ps1 appends the git SHA via
|
||||
SourceRevisionId, giving "1.1.0+feb1c7b".
|
||||
-->
|
||||
<Version>1.6.4</Version>
|
||||
<Version>1.7.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user