E3: correzioni della revisione di formati e fotogrammi
Le 16 osservazioni confermate della revisione, ognuna con la sua prova: - JPEG: il controllo stima la memoria di lavoro del decodificatore (progressivo), così un file che non si decodifica esce «troppo grande» e non «illeggibile». - Un EXIF che non si tiene lascia un EXIF minimo con l'orientamento, perché la foto convertita non esca girata. - Fotogrammi: istanti in millisecondi interi; la copia trova l'indice del nome dall'istante, non dall'ordine delle righe. - Video di durata sconosciuta misurati prima di registrare: contano nei limiti di 500 per richiesta e 5000 per video. - Rimuxaggio: la durata del segmento di elst passa nell'MP4, la fine tagliata resta nascosta (anche nei fotogrammi). - H.264: il punto di recupero vale come IDR solo con exact_match_flag. - MP3 in MP4: objectTypeIndication 0x69 fino a 24 kHz, 0x6B oltre. - Conversione della libreria: il lavoro toglie le righe di un formato spento o cambiato; spegnere toglie anche i «Non riuscito»; «Riprova» solo i formati di adesso; pausa per spazio prima di rileggere l'originale. - «Anche i N» conta e mette in coda solo il tipo che si cambia; le impostazioni dell'esportazione si salvano una per volta. - Eliminazione e «Tieni il più grande» scelgono i convertiti nella stessa transazione: nessun convertito orfano. - Un file arrivato tardi in un elemento vecchio mette in coda solo sé (file nuovo = salvato da quando il formato è scelto). - Zip dei fotogrammi a pezzi di 64 KB: un browser lento che legge non si interrompe, uno fermo sì. Decisioni in docs/decisioni.md (28/11), §4.10 della specifica precisato. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb79b05fda
commit
958cb71cd6
38 files changed
+1276
-222
No files matched your search
@@ -63,6 +63,69 @@ public sealed class Mp4RemuxerTests
|
||||
AssertSameSamples(before.Audio, source, after.Audio, output, "audio");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ATrimmedEndStaysHiddenInTheMp4()
|
||||
{
|
||||
// A passthrough trim: the edits show 0,3 s of video and of audio, the rest of the media is hidden.
|
||||
var es = ElementaryStream.Load("BA1_Sony_D");
|
||||
const int ShownFrames = 9; // 0,3 s: a whole number of milliseconds, as the movie timescale keeps the edit
|
||||
Assert.IsGreaterThan(ShownFrames + 3, es.Count);
|
||||
var shownVideo = (long)ShownFrames * TestVideos.FrameTicks;
|
||||
var mov = TestVideos.Mov(es, new MovOptions(Audio: true, AudioPriming: 1024, VideoTrim: shownVideo, AudioTrim: 13230));
|
||||
using var source = new MemoryStream(mov);
|
||||
var before = Read(source);
|
||||
Assert.AreEqual(shownVideo, before.Video!.EditSegmentDuration);
|
||||
Assert.AreEqual(13230L, before.Audio!.EditSegmentDuration);
|
||||
Assert.AreEqual(TimeSpan.FromSeconds((double)shownVideo / TestVideos.Timescale), before.Duration);
|
||||
|
||||
Assert.AreEqual(RemuxRefusal.None, Mp4Remuxer.Check(source, "clip.mov", out var plan, CancellationToken.None));
|
||||
using var output = new MemoryStream(Remux(plan!, source));
|
||||
var after = Read(output);
|
||||
|
||||
Assert.AreEqual(shownVideo, after.Video!.EditSegmentDuration, "the edits are carried over");
|
||||
Assert.AreEqual(13230L, after.Audio!.EditSegmentDuration);
|
||||
Assert.AreEqual((before.Audio.EditMediaTime, before.Video.EditMediaTime ?? 0), (after.Audio.EditMediaTime, after.Video.EditMediaTime ?? 0));
|
||||
Assert.AreEqual(before.Duration, after.Duration, "the MP4 lasts what the source shows");
|
||||
AssertSameSamples(before.Video, source, after.Video, output, "video");
|
||||
AssertSameSamples(before.Audio, source, after.Audio, output, "audio");
|
||||
|
||||
// A frame «oltre la fine» is the last one shown, never one the edit hides.
|
||||
using var reader = Febe.Core.Library.VideoFrameReader.Open(output, out var info);
|
||||
Assert.IsTrue(info.Available);
|
||||
var last = reader.Locate([TimeSpan.FromHours(1)]).Single();
|
||||
Assert.IsLessThan(TimeSpan.FromSeconds((double)shownVideo / TestVideos.Timescale), last.Actual);
|
||||
Assert.AreEqual(ShownFrames - 1, last.Sample);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(44100, 0x6B)]
|
||||
[DataRow(32000, 0x6B)]
|
||||
[DataRow(24000, 0x69)]
|
||||
[DataRow(22050, 0x69)]
|
||||
[DataRow(16000, 0x69)]
|
||||
public void Mp3IsLabelledMpeg1OrMpeg2AudioByItsRate(int rate, int objectType)
|
||||
{
|
||||
// ISO/IEC 14496-1 Table 5: 0x6B is ISO/IEC 11172-3 (MPEG-1, 32-48 kHz), 0x69 ISO/IEC 13818-3 (the lower rates).
|
||||
var mov = TestVideos.Mov(ElementaryStream.Load("BA1_Sony_D"), new MovOptions(Audio: true, Mp3: true, AudioRate: rate));
|
||||
using var source = new MemoryStream(mov);
|
||||
Assert.AreEqual(RemuxRefusal.None, Mp4Remuxer.Check(source, "clip.mov", out var plan, CancellationToken.None));
|
||||
var mp4 = Remux(plan!, source);
|
||||
|
||||
Assert.AreEqual(objectType, ObjectTypeIndication(mp4));
|
||||
using var output = new MemoryStream(mp4);
|
||||
Assert.AreEqual((AudioCodec.Mp3, rate), (Read(output).Audio!.Codec, Read(output).Audio!.SampleRate));
|
||||
}
|
||||
|
||||
/// <summary>The objectTypeIndication of the DecoderConfigDescriptor (tag 4) in the <c>esds</c> of a file.</summary>
|
||||
private static int ObjectTypeIndication(byte[] file)
|
||||
{
|
||||
var esds = file.AsSpan().IndexOf("esds"u8);
|
||||
Assert.IsGreaterThan(0, esds);
|
||||
var config = file.AsSpan(esds).IndexOf((ReadOnlySpan<byte>)[0x04, 0x80, 0x80, 0x80]);
|
||||
Assert.IsGreaterThan(0, config);
|
||||
return file[esds + config + 5];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ExtraTracksAreDroppedAndCountedAndMp3IsKept()
|
||||
{
|
||||
|
||||
@@ -340,24 +340,27 @@ internal static class TestVideos
|
||||
HevcConfiguration = es.Hevc ? es.AvcC : null,
|
||||
Language = o.Language,
|
||||
EmptyEditDuration = o.VideoEmptyEdit,
|
||||
EditMediaTime = o.VideoTrim > 0 ? 0 : null,
|
||||
EditSegmentDuration = o.VideoTrim > 0 ? o.VideoTrim : null,
|
||||
},
|
||||
};
|
||||
for (var track = 0; track < (o.Audio ? 1 : 0) + o.ExtraAudioTracks; track++)
|
||||
{
|
||||
var frames = (int)Math.Ceiling(es.Count / 30.0 * 44100 / 1024) + (o.AudioPriming > 0 ? 1 : 0);
|
||||
var frames = (int)Math.Ceiling(es.Count / 30.0 * o.AudioRate / 1024) + (o.AudioPriming > 0 ? 1 : 0);
|
||||
var payload = new byte[] { 0x21, 0x10, 0x04, 0x60, 0x8C, 0x1C, (byte)track };
|
||||
tracks.Add(new Mp4OutputTrack
|
||||
{
|
||||
IsVideo = false,
|
||||
Timescale = 44100,
|
||||
Timescale = o.AudioRate,
|
||||
Samples = [.. Enumerable.Range(0, frames).Select(i => new Mp4OutputSample(payload.Length, i * 1024L, i * 1024L, true))],
|
||||
WriteSample = (_, s) => s.Write(payload),
|
||||
AacConfiguration = o.Mp3 ? null : [0x12, 0x10], // AAC LC, 44.1 kHz, stereo
|
||||
IsMp3 = o.Mp3,
|
||||
SampleRate = 44100,
|
||||
SampleRate = o.AudioRate,
|
||||
Channels = 2,
|
||||
Language = o.Language,
|
||||
EditMediaTime = o.AudioPriming > 0 ? o.AudioPriming : null,
|
||||
EditSegmentDuration = o.AudioTrim > 0 ? o.AudioTrim : null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -624,6 +627,9 @@ internal static class TestVideos
|
||||
/// <param name="ExtraAudioTracks">Further audio tracks (an MP4 of Febe keeps one).</param>
|
||||
/// <param name="AudioPriming">Samples of AAC priming hidden by the audio edit (media time of the edit); 0: no edit.</param>
|
||||
/// <param name="VideoEmptyEdit">Ticks (of 30000 a second) before the video starts: an empty edit.</param>
|
||||
/// <param name="VideoTrim">Ticks (of 30000 a second) of video shown by its edit, the rest hidden (a trim); 0: all.</param>
|
||||
/// <param name="AudioRate">The sample rate (and timescale) of the audio; the AAC configuration always says 44,1 kHz.</param>
|
||||
/// <param name="AudioTrim">Samples (of 44100 a second) of audio shown by its edit after the priming; 0: all.</param>
|
||||
internal sealed record MovOptions(
|
||||
bool Audio = false,
|
||||
bool Mp3 = false,
|
||||
@@ -633,4 +639,7 @@ internal sealed record MovOptions(
|
||||
DateTimeOffset? Created = null,
|
||||
DateTimeOffset? Modified = null,
|
||||
long AudioPriming = 0,
|
||||
long VideoEmptyEdit = 0);
|
||||
long VideoEmptyEdit = 0,
|
||||
long VideoTrim = 0,
|
||||
long AudioTrim = 0,
|
||||
int AudioRate = 44100);
|
||||
Reference in new issue
Block a user