fix: address the phase 5 review

Video trash moves across volumes commit once the verified copy has its
name and leave an undeletable source whole behind a .leftover marker that
the next start settles; deletes rehash under the lease. Restores honour
the names renders are writing, and encoders never overwrite an output.
Routing floors at the stored settings' format, kindless stills read as
stills, star trails restart per loop, and settings the encoder ignored
become render warnings. The Videos section fits beside the player, plays
downloaded server copies, names blocked videos and says why actions are
off; the admin panel offers no download for sequences or missing files
and names a filtered sequence from its record.

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-05 04:11:02 +01:00
1 parent 6d87a1bc6d
commit 1be273d0e4
38 files changed
+958 -160

No files matched your search

@@ -33,6 +33,7 @@ public sealed class MediaFoundationEncoderSession : IVideoEncoderSession
private readonly Dictionary<long, long> _ticksByHns = [];
private readonly Dictionary<long, long> _durationByTicks = [];
private readonly Queue<long> _inputStarts = new();
private readonly List<EncoderSetting> _ignored = [];
private bool _providesSamples;
private uint _outputBufferSize;
private int _needInput;
@@ -58,6 +59,7 @@ public sealed class MediaFoundationEncoderSession : IVideoEncoderSession
if (UnlockAsync(transform))
_events = transform as IMFMediaEventGenerator ?? throw new NotSupportedException("Asynchronous MFT without an event generator");
if (transform as ICodecAPI is { } codecApi) ApplyCodecSettings(codecApi);
else _ignored.AddRange(Asked());
SetOutputType();
SetInputType();
ReadOutputStreamInfo();
@@ -157,7 +159,8 @@ public sealed class MediaFoundationEncoderSession : IVideoEncoderSession
_muxer.Complete();
_file.Flush(flushToDisk: true);
_file.Dispose();
AtomicFile.Commit(_tempPath, _settings.OutputPath);
// The render picked a free name: something that took it meanwhile (a restore) is never overwritten.
AtomicFile.CommitNew(_tempPath, _settings.OutputPath);
_completed = true;
Log.Info(LogCategory, $"\"{EncoderName}\" encoded {_framesIn} frames into {_framesOut} samples: {_settings.OutputPath}");
}
@@ -208,27 +211,51 @@ public sealed class MediaFoundationEncoderSession : IVideoEncoderSession
RateControl.Quality => MfNative.RateControlQuality,
_ => MfNative.RateControlUnconstrainedVbr,
};
SetCodecValue(api, MfGuids.CodecRateControlMode, ComVariant.Create(mode), "RateControlMode");
var asked = Asked().ToHashSet();
void Set(in Guid property, ComVariant value, string name, EncoderSetting setting)
{
if (!SetCodecValue(api, property, value, name) && asked.Contains(setting) && !_ignored.Contains(setting)) _ignored.Add(setting);
}
Set(MfGuids.CodecRateControlMode, ComVariant.Create(mode), "RateControlMode", EncoderSetting.RateControl);
if (_settings.RateControl == RateControl.Quality)
SetCodecValue(api, MfGuids.CodecQuality, ComVariant.Create((uint)Math.Clamp(_settings.Quality, 1, 100)), "Quality");
Set(MfGuids.CodecQuality, ComVariant.Create((uint)Math.Clamp(_settings.Quality, 1, 100)), "Quality", EncoderSetting.Quality);
else
SetCodecValue(api, MfGuids.CodecMeanBitRate, ComVariant.Create(BitRate), "MeanBitRate");
Set(MfGuids.CodecMeanBitRate, ComVariant.Create(BitRate), "MeanBitRate", EncoderSetting.BitRate);
var gop = _settings.GopLength > 0 ? _settings.GopLength : (int)Math.Max(1, Math.Round(_settings.FrameRate.Value));
SetCodecValue(api, MfGuids.CodecGopSize, ComVariant.Create((uint)gop), "GOPSize");
Set(MfGuids.CodecGopSize, ComVariant.Create((uint)gop), "GOPSize", EncoderSetting.KeyframeInterval);
var bFrames = _settings.Profile == CodecProfile.H264Baseline ? 0 : Math.Max(0, _settings.BFrames);
SetCodecValue(api, MfGuids.CodecBPictureCount, ComVariant.Create((uint)bFrames), "BPictureCount");
Set(MfGuids.CodecBPictureCount, ComVariant.Create((uint)bFrames), "BPictureCount", EncoderSetting.BFrames);
SetCodecValue(api, MfGuids.CodecLowLatencyMode, ComVariant.Create(false), "LowLatencyMode");
}
private static unsafe void SetCodecValue(ICodecAPI api, in Guid property, ComVariant value, string name)
/// <inheritdoc />
public IReadOnlyList<EncoderSetting> Ignored => _ignored;
/// <summary>
/// The settings that name a value of their own rather than the encoder's default, whose refusal the render reports: a rate
/// control other than VBR, its quality, a bit rate given, a keyframe interval given, a B-frame count other than the default.
/// </summary>
private IEnumerable<EncoderSetting> Asked()
{
if (_settings.RateControl != RateControl.Vbr) yield return EncoderSetting.RateControl;
if (_settings.RateControl == RateControl.Quality) yield return EncoderSetting.Quality;
else if (_settings.BitRate > 0) yield return EncoderSetting.BitRate;
if (_settings.GopLength > 0) yield return EncoderSetting.KeyframeInterval;
if (_settings.Profile != CodecProfile.H264Baseline && _settings.BFrames != EncodeSettings.DefaultBFrames) yield return EncoderSetting.BFrames;
}
/// <summary>Sets an ICodecAPI property; false (logged) when the encoder does not support it or refuses the value.</summary>
private static unsafe bool SetCodecValue(ICodecAPI api, in Guid property, ComVariant value, string name)
{
if (api.IsSupported(property) != 0)
{
Log.Debug(LogCategory, $"ICodecAPI {name} not supported by the encoder");
return;
return false;
}
var hr = api.SetValue(property, (nint)(&value));
if (hr < 0) Log.Debug(LogCategory, $"ICodecAPI {name} rejected (0x{hr:X8})");
return hr >= 0;
}
/// <summary>Requested bit rate, or the preset density (§11.4: 0.10/0.07/0.05 bits per pixel per frame) when unset.</summary>