From 38789162eb178c1d43395a3ea66f09ae937abe46 Mon Sep 17 00:00:00 2001 From: Phillip Fisher Date: Sat, 25 Feb 2023 11:29:41 -0600 Subject: [PATCH 01/30] Add chapters to FFProbe --- .../FFMpeg/Builders/MetaData/ChapterData.cs | 4 +++ FFMpegCore/FFProbe/FFProbe.cs | 2 +- FFMpegCore/FFProbe/FFProbeAnalysis.cs | 27 +++++++++++++++++++ FFMpegCore/FFProbe/IMediaAnalysis.cs | 5 +++- FFMpegCore/FFProbe/MediaAnalysis.cs | 13 +++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs index 77a47bd..d0b5bcb 100644 --- a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs +++ b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs @@ -6,11 +6,15 @@ public class ChapterData public TimeSpan Start { get; private set; } public TimeSpan End { get; private set; } + public TimeSpan Duration { get; private set; } + public ChapterData(string title, TimeSpan start, TimeSpan end) { Title = title; Start = start; End = end; + + Duration = end - start; } } } diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 8a7069e..d1032c6 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -213,7 +213,7 @@ private static void ThrowIfExitCodeNotZero(IProcessResult result) } private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions); + => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams -show_chapters \"{filePath}\"", ffOptions); private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions) => PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions); private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions) diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index b053d98..f3193ea 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -11,6 +11,9 @@ public class FFProbeAnalysis [JsonPropertyName("format")] public Format Format { get; set; } = null!; + [JsonPropertyName("chapters")] + public List Chapters { get; set; } = null!; + [JsonIgnore] public IReadOnlyList ErrorData { get; set; } = new List(); } @@ -129,6 +132,30 @@ public class Format : ITagsContainer public Dictionary Tags { get; set; } = null!; } + public class Chapter : ITagsContainer + { + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("time_base")] + public string TimeBase { get; set; } = null!; + + [JsonPropertyName("start")] + public int Start { get; set; } + + [JsonPropertyName("start_time")] + public string StartTime { get; set; } = null!; + + [JsonPropertyName("end")] + public int End { get; set; } + + [JsonPropertyName("end_time")] + public string EndTime { get; set; } = null!; + + [JsonPropertyName("tags")] + public Dictionary Tags { get; set; } = null!; + } + public interface IDispositionContainer { Dictionary Disposition { get; set; } diff --git a/FFMpegCore/FFProbe/IMediaAnalysis.cs b/FFMpegCore/FFProbe/IMediaAnalysis.cs index 47f47e4..d99992a 100644 --- a/FFMpegCore/FFProbe/IMediaAnalysis.cs +++ b/FFMpegCore/FFProbe/IMediaAnalysis.cs @@ -1,9 +1,12 @@ -namespace FFMpegCore +using FFMpegCore.Builders.MetaData; + +namespace FFMpegCore { public interface IMediaAnalysis { TimeSpan Duration { get; } MediaFormat Format { get; } + List Chapters { get; } AudioStream? PrimaryAudioStream { get; } VideoStream? PrimaryVideoStream { get; } SubtitleStream? PrimarySubtitleStream { get; } diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 9fce0fe..887baeb 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -1,4 +1,5 @@ using System.Text.RegularExpressions; +using FFMpegCore.Builders.MetaData; namespace FFMpegCore { @@ -7,6 +8,7 @@ internal class MediaAnalysis : IMediaAnalysis internal MediaAnalysis(FFProbeAnalysis analysis) { Format = ParseFormat(analysis.Format); + Chapters = analysis.Chapters.Select(c => ParseChapter(c)).ToList(); VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList(); AudioStreams = analysis.Streams.Where(stream => stream.CodecType == "audio").Select(ParseAudioStream).ToList(); SubtitleStreams = analysis.Streams.Where(stream => stream.CodecType == "subtitle").Select(ParseSubtitleStream).ToList(); @@ -28,6 +30,15 @@ private MediaFormat ParseFormat(Format analysisFormat) }; } + private ChapterData ParseChapter(Chapter analysisChapter) + { + var title = analysisChapter.Tags.FirstOrDefault(t => t.Key == "title").Value; + var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime); + var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime); + + return new ChapterData(title, start, end); + } + public TimeSpan Duration => new[] { Format.Duration, @@ -37,6 +48,8 @@ private MediaFormat ParseFormat(Format analysisFormat) public MediaFormat Format { get; } + public List Chapters { get; } + public AudioStream? PrimaryAudioStream => AudioStreams.OrderBy(stream => stream.Index).FirstOrDefault(); public VideoStream? PrimaryVideoStream => VideoStreams.OrderBy(stream => stream.Index).FirstOrDefault(); public SubtitleStream? PrimarySubtitleStream => SubtitleStreams.OrderBy(stream => stream.Index).FirstOrDefault(); From 718371505cb78f1bc14ee78f413be88af53e6167 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Mon, 6 Mar 2023 17:22:08 +1300 Subject: [PATCH 02/30] Add .gif file extension --- FFMpegCore/FFMpeg/Enums/FileExtension.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore/FFMpeg/Enums/FileExtension.cs b/FFMpegCore/FFMpeg/Enums/FileExtension.cs index b5e775d..f3067ba 100644 --- a/FFMpegCore/FFMpeg/Enums/FileExtension.cs +++ b/FFMpegCore/FFMpeg/Enums/FileExtension.cs @@ -20,5 +20,6 @@ public static string Extension(this Codec type) public static readonly string WebM = VideoType.WebM.Extension; public static readonly string Png = ".png"; public static readonly string Mp3 = ".mp3"; + public static readonly string Gif = ".gif"; } } From 4dbbf345d4912283dc63a92d71d7400b4501783c Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Mon, 6 Mar 2023 17:25:08 +1300 Subject: [PATCH 03/30] Add "GifPalettArgument" for outputting GIFs --- .../FFMpeg/Arguments/GifPalettArgument.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs b/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs new file mode 100644 index 0000000..408832d --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs @@ -0,0 +1,21 @@ +using System.Drawing; + +namespace FFMpegCore.Arguments +{ + public class GifPalettArgument : IArgument + { + private readonly int _fps; + + private readonly Size? _size; + + public GifPalettArgument(int fps, Size? size) + { + _fps = fps; + _size = size; + } + + private string ScaleText => _size.HasValue ? $"scale=w={_size.Value.Width}:h={_size.Value.Height}," : string.Empty; + + public string Text => $"-filter_complex \"[0:v] fps={_fps},{ScaleText}split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer\""; + } +} From b7fd9890da19e32d9a14c8169d535f66cc2a63ae Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:07:30 +1300 Subject: [PATCH 04/30] Add GifPallet argument builder --- FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index cc49c5f..635ef29 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -76,6 +76,7 @@ public FFMpegArgumentOptions DeselectStreams(IEnumerable streamIndices, int public FFMpegArgumentOptions WithAudibleEncryptionKeys(string key, string iv) => WithArgument(new AudibleEncryptionKeyArgument(key, iv)); public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version)); + public FFMpegArgumentOptions WithGifPalettArgument(Size? size, int fps = 12) => WithArgument(new GifPalettArgument(fps, size)); public FFMpegArgumentOptions WithArgument(IArgument argument) { From 19c177a248d7a627671b2162534089446855fc6b Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:19:03 +1300 Subject: [PATCH 05/30] Receive stream index as an argument for generating GIFs --- FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs | 7 +++++-- FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs b/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs index 408832d..9c95045 100644 --- a/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs @@ -4,18 +4,21 @@ namespace FFMpegCore.Arguments { public class GifPalettArgument : IArgument { + private readonly int _streamIndex; + private readonly int _fps; private readonly Size? _size; - public GifPalettArgument(int fps, Size? size) + public GifPalettArgument(int streamIndex, int fps, Size? size) { + _streamIndex = streamIndex; _fps = fps; _size = size; } private string ScaleText => _size.HasValue ? $"scale=w={_size.Value.Width}:h={_size.Value.Height}," : string.Empty; - public string Text => $"-filter_complex \"[0:v] fps={_fps},{ScaleText}split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer\""; + public string Text => $"-filter_complex \"[{_streamIndex}:v] fps={_fps},{ScaleText}split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer\""; } } diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index 635ef29..25394e2 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -76,7 +76,7 @@ public FFMpegArgumentOptions DeselectStreams(IEnumerable streamIndices, int public FFMpegArgumentOptions WithAudibleEncryptionKeys(string key, string iv) => WithArgument(new AudibleEncryptionKeyArgument(key, iv)); public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version)); - public FFMpegArgumentOptions WithGifPalettArgument(Size? size, int fps = 12) => WithArgument(new GifPalettArgument(fps, size)); + public FFMpegArgumentOptions WithGifPalettArgument(int streamIndex, Size? size, int fps = 12) => WithArgument(new GifPalettArgument(streamIndex, fps, size)); public FFMpegArgumentOptions WithArgument(IArgument argument) { From d14ef2268f6b5ae9b9027d181db85dd1d08fe4ba Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:31:45 +1300 Subject: [PATCH 06/30] Add "BuildGifSnapshotArguments" method --- FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs index 4456837..2645867 100644 --- a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs +++ b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs @@ -31,6 +31,31 @@ public static (FFMpegArguments, Action outputOptions) Bui .Resize(size)); } + public static (FFMpegArguments, Action outputOptions) BuildGifSnapshotArguments( + string input, + IMediaAnalysis source, + Size? size = null, + TimeSpan? captureTime = null, + TimeSpan? duration = null, + int? streamIndex = null, + int fps = 12) + { + var defaultGifOutputSize = new Size(480, -1); + + captureTime ??= TimeSpan.FromSeconds(source.Duration.TotalSeconds / 3); + size = PrepareSnapshotSize(source, size) ?? defaultGifOutputSize; + streamIndex ??= source.PrimaryVideoStream?.Index + ?? source.VideoStreams.FirstOrDefault()?.Index + ?? 0; + + return (FFMpegArguments + .FromFileInput(input, false, options => options + .Seek(captureTime) + .WithDuration(duration)), + options => options + .WithGifPalettArgument((int)streamIndex, size, fps)); + } + private static Size? PrepareSnapshotSize(IMediaAnalysis source, Size? wantedSize) { if (wantedSize == null || (wantedSize.Value.Height <= 0 && wantedSize.Value.Width <= 0) || source.PrimaryVideoStream == null) From a90918eac69500f914fb171a757d82f70d20f1f9 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:41:52 +1300 Subject: [PATCH 07/30] Add "GifSnapshot" and "GifSnapshotAsync" methods --- FFMpegCore/FFMpeg/FFMpeg.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index 362a865..6cd0cd0 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -57,6 +57,36 @@ public static async Task SnapshotAsync(string input, string output, Size? .ProcessAsynchronously(); } + public static bool GifSnapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int ? streamIndex = null) + { + if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif) + { + output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Gif); + } + + var source = FFProbe.Analyse(input); + var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex); + + return arguments + .OutputToFile(output, true, outputOptions) + .ProcessSynchronously(); + } + + public static async Task GifSnapshotAsync(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null) + { + if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif) + { + output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Gif); + } + + var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false); + var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex); + + return await arguments + .OutputToFile(output, true, outputOptions) + .ProcessAsynchronously(); + } + /// /// Converts an image sequence to a video. /// From c218b3592bc9e70511d8788e6ad674b3d311efcc Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:44:33 +1300 Subject: [PATCH 08/30] Add unit tests --- FFMpegCore.Test/ArgumentBuilderTest.cs | 36 ++++++++++++++- FFMpegCore.Test/VideoTest.cs | 61 +++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 2c550c9..efe7f7b 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -1,4 +1,5 @@ -using FFMpegCore.Arguments; +using System.Drawing; +using FFMpegCore.Arguments; using FFMpegCore.Enums; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -537,5 +538,38 @@ public void Builder_BuildString_PadFilter_Alt() "-i \"input.mp4\" -vf \"pad=aspect=4/3:x=(ow-iw)/2:y=(oh-ih)/2:color=violet:eval=frame\" \"output.mp4\"", str); } + + [TestMethod] + public void Builder_BuildString_GifPallet() + { + var streamIndex = 0; + var size = new Size(640, 480); + + var str = FFMpegArguments + .FromFileInput("input.mp4") + .OutputToFile("output.gif", false, opt => opt + .WithGifPalettArgument(streamIndex, size)) + .Arguments; + + Assert.AreEqual($""" + -i "input.mp4" -filter_complex "[0:v] fps=12,scale=w={size.Width}:h={size.Height},split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer" "output.gif" + """, str); + } + + [TestMethod] + public void Builder_BuildString_GifPallet_NullSize_FpsSupplied() + { + var streamIndex = 1; + + var str = FFMpegArguments + .FromFileInput("input.mp4") + .OutputToFile("output.gif", false, opt => opt + .WithGifPalettArgument(streamIndex, null, 10)) + .Arguments; + + Assert.AreEqual($""" + -i "input.mp4" -filter_complex "[{streamIndex}:v] fps=10,split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer" "output.gif" + """, str); + } } } diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 4403065..5071a48 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1,4 +1,5 @@ -using System.Drawing.Imaging; +using System.Drawing; +using System.Drawing.Imaging; using System.Runtime.Versioning; using System.Text; using FFMpegCore.Arguments; @@ -479,6 +480,64 @@ public void Video_Snapshot_PersistSnapshot() Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName); } + [TestMethod, Timeout(BaseTimeoutMilliseconds)] + public void Video_GifSnapshot_PersistSnapshot() + { + using var outputPath = new TemporaryFile("out.gif"); + var input = FFProbe.Analyse(TestResources.Mp4Video); + + FFMpeg.GifSnapshot(TestResources.Mp4Video, outputPath, captureTime: TimeSpan.FromSeconds(0)); + + var analysis = FFProbe.Analyse(outputPath); + Assert.AreNotEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width); + Assert.AreNotEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height); + Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName); + } + + [TestMethod, Timeout(BaseTimeoutMilliseconds)] + public void Video_GifSnapshot_PersistSnapshot_SizeSupplied() + { + using var outputPath = new TemporaryFile("out.gif"); + var input = FFProbe.Analyse(TestResources.Mp4Video); + var desiredGifSize = new Size(320, 240); + + FFMpeg.GifSnapshot(TestResources.Mp4Video, outputPath, desiredGifSize, captureTime: TimeSpan.FromSeconds(0)); + + var analysis = FFProbe.Analyse(outputPath); + Assert.AreNotEqual(input.PrimaryVideoStream!.Width, desiredGifSize.Width); + Assert.AreNotEqual(input.PrimaryVideoStream.Height, desiredGifSize.Height); + Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName); + } + + [TestMethod, Timeout(BaseTimeoutMilliseconds)] + public async Task Video_GifSnapshot_PersistSnapshotAsync() + { + using var outputPath = new TemporaryFile("out.gif"); + var input = FFProbe.Analyse(TestResources.Mp4Video); + + await FFMpeg.GifSnapshotAsync(TestResources.Mp4Video, outputPath, captureTime: TimeSpan.FromSeconds(0)); + + var analysis = FFProbe.Analyse(outputPath); + Assert.AreNotEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width); + Assert.AreNotEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height); + Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName); + } + + [TestMethod, Timeout(BaseTimeoutMilliseconds)] + public async Task Video_GifSnapshot_PersistSnapshotAsync_SizeSupplied() + { + using var outputPath = new TemporaryFile("out.gif"); + var input = FFProbe.Analyse(TestResources.Mp4Video); + var desiredGifSize = new Size(320, 240); + + await FFMpeg.GifSnapshotAsync(TestResources.Mp4Video, outputPath, desiredGifSize, captureTime: TimeSpan.FromSeconds(0)); + + var analysis = FFProbe.Analyse(outputPath); + Assert.AreNotEqual(input.PrimaryVideoStream!.Width, desiredGifSize.Width); + Assert.AreNotEqual(input.PrimaryVideoStream.Height, desiredGifSize.Height); + Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName); + } + [TestMethod, Timeout(BaseTimeoutMilliseconds)] public void Video_Join() { From 62a9ed628185b2d7a0ab9dc32e61fa5784b2ef6f Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:49:18 +1300 Subject: [PATCH 09/30] Update README to add information about GIF Snapshots --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index d2a9633..365d0be 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,17 @@ var bitmap = FFMpeg.Snapshot(inputPath, new Size(200, 400), TimeSpan.FromMinutes FFMpeg.Snapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromMinutes(1)); ``` +### You can also capture GIF snapshots from a video file: +```csharp +FFMpeg.GifSnapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromSeconds(10)); + +// or async +await FFMpeg.GifSnapshotAsync(inputPath, outputPath, new Size(200, 400), TimeSpan.FromSeconds(10)); + +// you can also supply -1 to either one of Width/Height Size properties if you'd like FFMPEG to resize while maintaining the aspect ratio +await FFMpeg.GifSnapshotAsync(inputPath, outputPath, new Size(480, -1), TimeSpan.FromSeconds(10)); +``` + ### Join video parts into one single file: ```csharp FFMpeg.Join(@"..\joined_video.mp4", From 7569669f526baafcc0f23421d917d60376156231 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:55:11 +1300 Subject: [PATCH 10/30] Fix Palette typos --- FFMpegCore.Test/ArgumentBuilderTest.cs | 8 ++++---- .../{GifPalettArgument.cs => GifPaletteArgument.cs} | 4 ++-- FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 2 +- FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) rename FFMpegCore/FFMpeg/Arguments/{GifPalettArgument.cs => GifPaletteArgument.cs} (83%) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index efe7f7b..30adabd 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -540,7 +540,7 @@ public void Builder_BuildString_PadFilter_Alt() } [TestMethod] - public void Builder_BuildString_GifPallet() + public void Builder_BuildString_GifPalette() { var streamIndex = 0; var size = new Size(640, 480); @@ -548,7 +548,7 @@ public void Builder_BuildString_GifPallet() var str = FFMpegArguments .FromFileInput("input.mp4") .OutputToFile("output.gif", false, opt => opt - .WithGifPalettArgument(streamIndex, size)) + .WithGifPaletteArgument(streamIndex, size)) .Arguments; Assert.AreEqual($""" @@ -557,14 +557,14 @@ public void Builder_BuildString_GifPallet() } [TestMethod] - public void Builder_BuildString_GifPallet_NullSize_FpsSupplied() + public void Builder_BuildString_GifPalette_NullSize_FpsSupplied() { var streamIndex = 1; var str = FFMpegArguments .FromFileInput("input.mp4") .OutputToFile("output.gif", false, opt => opt - .WithGifPalettArgument(streamIndex, null, 10)) + .WithGifPaletteArgument(streamIndex, null, 10)) .Arguments; Assert.AreEqual($""" diff --git a/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs b/FFMpegCore/FFMpeg/Arguments/GifPaletteArgument.cs similarity index 83% rename from FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs rename to FFMpegCore/FFMpeg/Arguments/GifPaletteArgument.cs index 9c95045..ac67fcd 100644 --- a/FFMpegCore/FFMpeg/Arguments/GifPalettArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/GifPaletteArgument.cs @@ -2,7 +2,7 @@ namespace FFMpegCore.Arguments { - public class GifPalettArgument : IArgument + public class GifPaletteArgument : IArgument { private readonly int _streamIndex; @@ -10,7 +10,7 @@ public class GifPalettArgument : IArgument private readonly Size? _size; - public GifPalettArgument(int streamIndex, int fps, Size? size) + public GifPaletteArgument(int streamIndex, int fps, Size? size) { _streamIndex = streamIndex; _fps = fps; diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index 25394e2..4930b52 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -76,7 +76,7 @@ public FFMpegArgumentOptions DeselectStreams(IEnumerable streamIndices, int public FFMpegArgumentOptions WithAudibleEncryptionKeys(string key, string iv) => WithArgument(new AudibleEncryptionKeyArgument(key, iv)); public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version)); - public FFMpegArgumentOptions WithGifPalettArgument(int streamIndex, Size? size, int fps = 12) => WithArgument(new GifPalettArgument(streamIndex, fps, size)); + public FFMpegArgumentOptions WithGifPaletteArgument(int streamIndex, Size? size, int fps = 12) => WithArgument(new GifPaletteArgument(streamIndex, fps, size)); public FFMpegArgumentOptions WithArgument(IArgument argument) { diff --git a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs index 2645867..0d9b414 100644 --- a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs +++ b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs @@ -53,7 +53,7 @@ public static (FFMpegArguments, Action outputOptions) Bui .Seek(captureTime) .WithDuration(duration)), options => options - .WithGifPalettArgument((int)streamIndex, size, fps)); + .WithGifPaletteArgument((int)streamIndex, size, fps)); } private static Size? PrepareSnapshotSize(IMediaAnalysis source, Size? wantedSize) From 3dc2fff0ac8c67567ab5e12cfba2822ac9fbbaf6 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 17:04:23 +1300 Subject: [PATCH 11/30] Fix whitespace formatting linting error --- FFMpegCore/FFMpeg/FFMpeg.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index 6cd0cd0..a8de12b 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -57,7 +57,7 @@ public static async Task SnapshotAsync(string input, string output, Size? .ProcessAsynchronously(); } - public static bool GifSnapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int ? streamIndex = null) + public static bool GifSnapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null) { if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif) { From 943662aa15e8cf73dce0b1a8b93ffe8e8bae274b Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 15 Mar 2023 13:26:11 +0100 Subject: [PATCH 12/30] Bump nuget version --- FFMpegCore/FFMpegCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index db5abd1..2af7f16 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -3,7 +3,7 @@ true A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications - 5.0.2 + 5.1.0 ../nupkg From ba78512cb92c9f59d22d713a026da68118a9e9f4 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 12 Apr 2023 16:30:46 +0200 Subject: [PATCH 13/30] ChapterData.Duration as computed property --- FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs index d0b5bcb..e278408 100644 --- a/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs +++ b/FFMpegCore/FFMpeg/Builders/MetaData/ChapterData.cs @@ -6,15 +6,13 @@ public class ChapterData public TimeSpan Start { get; private set; } public TimeSpan End { get; private set; } - public TimeSpan Duration { get; private set; } + public TimeSpan Duration => End - Start; public ChapterData(string title, TimeSpan start, TimeSpan end) { Title = title; Start = start; End = end; - - Duration = end - start; } } } From 0ac351493c2065945777b73e65fc527c92e7c310 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 12 Apr 2023 16:31:26 +0200 Subject: [PATCH 14/30] Verify Chapters property is initialized to non-null in test --- FFMpegCore.Test/FFProbeTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..38ec6cf 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -105,6 +105,7 @@ public void Probe_Success() { var info = FFProbe.Analyse(TestResources.Mp4Video); Assert.AreEqual(3, info.Duration.Seconds); + Assert.AreEqual(0, info.Chapters.Count); Assert.AreEqual("5.1", info.PrimaryAudioStream!.ChannelLayout); Assert.AreEqual(6, info.PrimaryAudioStream.Channels); From b2488303cf8451a679af5717b28dc5b6769d6b85 Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 21:47:36 +0200 Subject: [PATCH 15/30] feature: custom ffprobe arguments --- FFMpegCore/FFProbe/FFProbe.cs | 64 +++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 8a7069e..ddff026 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -10,52 +10,52 @@ namespace FFMpegCore { public static class FFProbe { - public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null) + public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var processArguments = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var processArguments = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = processArguments.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null) + public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseFramesOutput(result); } - public static FFProbePackets GetPackets(string filePath, FFOptions? ffOptions = null) + public static FFProbePackets GetPackets(string filePath, FFOptions? ffOptions = null, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParsePacketsOutput(result); } - public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null) + public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null, string? customArguments = null) { - var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null) + public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null, string? customArguments = null) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); - var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current, customArguments); pipeArgument.Pre(); var task = instance.StartAndWaitForExitAsync(); @@ -75,57 +75,57 @@ public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null) return ParseOutput(result); } - public static async Task AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null) + public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null, string? customArguments = null) { - var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = instance.StartAndWaitForExit(); ThrowIfExitCodeNotZero(result); return ParseFramesOutput(result); } - public static async Task GetFramesAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task GetFramesAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); return ParseFramesOutput(result); } - public static async Task GetPacketsAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task GetPacketsAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { ThrowIfInputFileDoesNotExist(filePath); - var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PreparePacketAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); return ParsePacketsOutput(result); } - public static async Task AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { - var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); ThrowIfExitCodeNotZero(result); return ParseOutput(result); } - public static async Task AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); - var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareStreamAnalysisInstance(pipeArgument.PipePath, ffOptions ?? GlobalFFOptions.Current, customArguments); pipeArgument.Pre(); var task = instance.StartAndWaitForExitAsync(cancellationToken); @@ -148,9 +148,9 @@ public static async Task AnalyseAsync(Stream stream, FFOptions? return ParseOutput(result); } - public static async Task GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default) + public static async Task GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default, string? customArguments = null) { - var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current); + var instance = PrepareFrameAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); return ParseFramesOutput(result); } @@ -212,18 +212,18 @@ private static void ThrowIfExitCodeNotZero(IProcessResult result) } } - private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions); - private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions); - private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions) - => PrepareInstance($"-loglevel error -print_format json -show_packets -v quiet -sexagesimal \"{filePath}\"", ffOptions); + private static ProcessArguments PrepareStreamAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments) + => PrepareInstance($"-loglevel error -print_format json -show_format -sexagesimal -show_streams \"{filePath}\"", ffOptions, customArguments); + private static ProcessArguments PrepareFrameAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments) + => PrepareInstance($"-loglevel error -print_format json -show_frames -v quiet -sexagesimal \"{filePath}\"", ffOptions, customArguments); + private static ProcessArguments PreparePacketAnalysisInstance(string filePath, FFOptions ffOptions, string? customArguments) + => PrepareInstance($"-loglevel error -print_format json -show_packets -v quiet -sexagesimal \"{filePath}\"", ffOptions, customArguments); - private static ProcessArguments PrepareInstance(string arguments, FFOptions ffOptions) + private static ProcessArguments PrepareInstance(string arguments, FFOptions ffOptions, string? customArguments) { FFProbeHelper.RootExceptionCheck(); FFProbeHelper.VerifyFFProbeExists(ffOptions); - var startInfo = new ProcessStartInfo(GlobalFFOptions.GetFFProbeBinaryPath(ffOptions), arguments) + var startInfo = new ProcessStartInfo(GlobalFFOptions.GetFFProbeBinaryPath(ffOptions), $"{arguments} {customArguments}") { StandardOutputEncoding = ffOptions.Encoding, StandardErrorEncoding = ffOptions.Encoding, From 4b0cd9239e563f630e0f54f5482f415f003e80ee Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 21:57:20 +0200 Subject: [PATCH 16/30] Add test --- FFMpegCore.Test/FFProbeTests.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..0d58f43 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -1,4 +1,4 @@ -using FFMpegCore.Test.Resources; +using FFMpegCore.Test.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace FFMpegCore.Test @@ -235,5 +235,12 @@ public async Task Probe_Success_32BitWavBitDepth_Async() Assert.IsNotNull(info.PrimaryAudioStream); Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth); } + + [TestMethod] + public void Probe_Success_Custom_Arguments() + { + var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: world\""); + Assert.AreEqual(3, info.Duration.Seconds); + } } } From 66c166f2e8b2f3d486f2b2477ec546e625cf1bac Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 22:07:22 +0200 Subject: [PATCH 17/30] Try fix encoding --- FFMpegCore.Test/FFProbeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 0d58f43..ffdf9e9 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -239,7 +239,7 @@ public async Task Probe_Success_32BitWavBitDepth_Async() [TestMethod] public void Probe_Success_Custom_Arguments() { - var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: world\""); + var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); Assert.AreEqual(3, info.Duration.Seconds); } } From 338274b5009c11a4c69b5cdfef4886942b48a630 Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 22:10:37 +0200 Subject: [PATCH 18/30] Try fix encoding 2 --- FFMpegCore.Test/FFProbeTests.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index ffdf9e9..9da819a 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -1,4 +1,4 @@ -using FFMpegCore.Test.Resources; +using FFMpegCore.Test.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace FFMpegCore.Test @@ -235,12 +235,5 @@ public async Task Probe_Success_32BitWavBitDepth_Async() Assert.IsNotNull(info.PrimaryAudioStream); Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth); } - - [TestMethod] - public void Probe_Success_Custom_Arguments() - { - var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); - Assert.AreEqual(3, info.Duration.Seconds); - } } } From bf06a8059be2730a462848f601cf5d5d2bf70873 Mon Sep 17 00:00:00 2001 From: vfrz Date: Wed, 12 Apr 2023 22:14:23 +0200 Subject: [PATCH 19/30] Add test again --- FFMpegCore.Test/FFProbeTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..05ec92f 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -235,5 +235,12 @@ public async Task Probe_Success_32BitWavBitDepth_Async() Assert.IsNotNull(info.PrimaryAudioStream); Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth); } + + [TestMethod] + public void Probe_Success_Custom_Arguments() + { + var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); + Assert.AreEqual(3, info.Duration.Seconds); + } } } From d9c4595eec61adeed497c4799aa3cbd89a2c0c47 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Fri, 21 Apr 2023 11:07:56 +0800 Subject: [PATCH 20/30] fix: readme minor mistakes. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 365d0be..33f7ddf 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ FFMpeg.Join(@"..\joined_video.mp4", ``` csharp FFMpeg.SubVideo(inputPath, outputPath, - TimeSpan.FromSeconds(0) + TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30) ); ``` From a920ab2bc15aaed67817dac09276141d63ab6f11 Mon Sep 17 00:00:00 2001 From: Devedse Date: Fri, 5 May 2023 12:42:27 +0200 Subject: [PATCH 21/30] Fix issue where ffmpeg can't be found if x64/x86 folders exist without ffmpeg in there --- FFMpegCore/GlobalFFOptions.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/FFMpegCore/GlobalFFOptions.cs b/FFMpegCore/GlobalFFOptions.cs index 209e137..49cac16 100644 --- a/FFMpegCore/GlobalFFOptions.cs +++ b/FFMpegCore/GlobalFFOptions.cs @@ -30,12 +30,23 @@ private static string GetFFBinaryPath(string name, FFOptions ffOptions) } var target = Environment.Is64BitProcess ? "x64" : "x86"; - if (Directory.Exists(Path.Combine(ffOptions.BinaryFolder, target))) + var possiblePaths = new List() { - ffName = Path.Combine(target, ffName); + Path.Combine(ffOptions.BinaryFolder, target), + ffOptions.BinaryFolder + }; + + foreach (var possiblePath in possiblePaths) + { + var possibleFFMpegPath = Path.Combine(possiblePath, ffName); + if (File.Exists(possibleFFMpegPath)) + { + return possibleFFMpegPath; + } } - return Path.Combine(ffOptions.BinaryFolder, ffName); + //Fall back to the assumption this tool exists in the PATH + return ffName; } private static FFOptions LoadFFOptions() From 69b01c91c61cf1878ca5f5e99b3056266a456adb Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 17 May 2023 11:40:20 +1200 Subject: [PATCH 22/30] Add CopyCodecArgument --- FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs b/FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs new file mode 100644 index 0000000..8ea3484 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/CopyCodecArgument.cs @@ -0,0 +1,10 @@ +namespace FFMpegCore.Arguments +{ + /// + /// Represents a copy codec parameter + /// + public class CopyCodecArgument : IArgument + { + public string Text => $"-codec copy"; + } +} From 643952db7bf11e611e7e50c786fc105813fa02e3 Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 17 May 2023 11:40:40 +1200 Subject: [PATCH 23/30] Add "WithCopyCodec" option --- FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index 4930b52..6a6586c 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -77,6 +77,7 @@ public FFMpegArgumentOptions DeselectStreams(IEnumerable streamIndices, int public FFMpegArgumentOptions WithAudibleActivationBytes(string activationBytes) => WithArgument(new AudibleEncryptionKeyArgument(activationBytes)); public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version)); public FFMpegArgumentOptions WithGifPaletteArgument(int streamIndex, Size? size, int fps = 12) => WithArgument(new GifPaletteArgument(streamIndex, fps, size)); + public FFMpegArgumentOptions WithCopyCodec() => WithArgument(new CopyCodecArgument()); public FFMpegArgumentOptions WithArgument(IArgument argument) { From 6c2311c86904a87339dc542160ae6b5ece18b24c Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Wed, 17 May 2023 11:41:13 +1200 Subject: [PATCH 24/30] Update "SaveM3U8Stream" method to use "WithCopyCodec" option --- FFMpegCore/FFMpeg/FFMpeg.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index a8de12b..820d9fb 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -333,7 +333,10 @@ public static bool SaveM3U8Stream(Uri uri, string output) } return FFMpegArguments - .FromUrlInput(uri) + .FromUrlInput(uri, options => + { + options.WithCopyCodec(); + }) .OutputToFile(output) .ProcessSynchronously(); } From 42f9005d5973225e92f2a69af452a79f32319ef6 Mon Sep 17 00:00:00 2001 From: Prakash Duggaraju Date: Fri, 8 Sep 2023 13:05:58 -0700 Subject: [PATCH 25/30] Add support for multiple outputs and tee muxer. A single input can be encoded simultaneously to multiple oputs or muxed in multiple formats --- FFMpegCore.Test/ArgumentBuilderTest.cs | 40 +++++++++++++ .../FFMpeg/Arguments/OutputTeeArgument.cs | 57 +++++++++++++++++++ FFMpegCore/FFMpeg/FFMpegArguments.cs | 15 +++++ FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs | 29 ++++++++++ 4 files changed, 141 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/OutputTeeArgument.cs create mode 100644 FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 30adabd..cf455c8 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -571,5 +571,45 @@ public void Builder_BuildString_GifPalette_NullSize_FpsSupplied() -i "input.mp4" -filter_complex "[{streamIndex}:v] fps=10,split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer" "output.gif" """, str); } + + [TestMethod] + public void Builder_BuildString_MultiOutput() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .MultiOutput(args => args + .OutputToFile("output.mp4", overwrite: true, args => args.CopyChannel()) + .OutputToFile("output.ts", overwrite: false, args => args.CopyChannel().ForceFormat("mpegts")) + .OutputToUrl("http://server/path", options => options.ForceFormat("webm"))) + .Arguments; + Assert.AreEqual($""" + -i "input.mp4" -c:a copy -c:v copy "output.mp4" -y -c:a copy -c:v copy -f mpegts "output.ts" -f webm http://server/path + """, str); + } + + [TestMethod] + public void Builder_BuildString_MBROutput() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .MultiOutput(args => args + .OutputToFile("sd.mp4", overwrite: true, args => args.Resize(1200, 720)) + .OutputToFile("hd.mp4", overwrite: false, args => args.Resize(1920, 1080))) + .Arguments; + Assert.AreEqual($""" + -i "input.mp4" -s 1200x720 "sd.mp4" -y -s 1920x1080 "hd.mp4" + """, str); + } + + [TestMethod] + public void Builder_BuildString_TeeOutput() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .OutputToTee(args => args + .OutputToFile("output.mp4", overwrite: false, args => args.WithFastStart()) + .OutputToUrl("http://server/path", options => options.ForceFormat("mpegts").SelectStream(0, channel: Channel.Video))) + .Arguments; + Assert.AreEqual($""" + -i "input.mp4" -f tee "[movflags=faststart]output.mp4|[f=mpegts:select=\'0:v:0\']http://server/path" + """, str); + } } } diff --git a/FFMpegCore/FFMpeg/Arguments/OutputTeeArgument.cs b/FFMpegCore/FFMpeg/Arguments/OutputTeeArgument.cs new file mode 100644 index 0000000..974b928 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/OutputTeeArgument.cs @@ -0,0 +1,57 @@ + +namespace FFMpegCore.Arguments +{ + internal class OutputTeeArgument : IOutputArgument + { + private readonly FFMpegMultiOutputOptions _options; + + public OutputTeeArgument(FFMpegMultiOutputOptions options) + { + if (options.Outputs.Count == 0) + { + throw new ArgumentException("Atleast one output must be specified.", nameof(options)); + } + + _options = options; + } + + public string Text => $"-f tee \"{string.Join("|", _options.Outputs.Select(MapOptions))}\""; + + public Task During(CancellationToken cancellationToken = default) => Task.CompletedTask; + + public void Post() + { + } + + public void Pre() + { + } + + private static string MapOptions(FFMpegArgumentOptions option) + { + var optionPrefix = string.Empty; + if (option.Arguments.Count > 1) + { + var options = option.Arguments.Take(option.Arguments.Count - 1); + optionPrefix = $"[{string.Join(":", options.Select(MapArgument))}]"; + } + + var output = option.Arguments.OfType().Single(); + return $"{optionPrefix}{output.Text.Trim('"')}"; + } + + private static string MapArgument(IArgument argument) + { + if (argument is MapStreamArgument map) + { + return map.Text.Replace("-map ", "select=\\'") + "\\'"; + } + else if (argument is BitStreamFilterArgument bitstreamFilter) + { + return bitstreamFilter.Text.Replace("-bsf:", "bsfs/").Replace(' ', '='); + } + + return argument.Text.TrimStart('-').Replace(' ', '='); + } + } +} diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index 1819cff..cfc6d9d 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -71,6 +71,21 @@ private FFMpegArgumentProcessor ToProcessor(IOutputArgument argument, Action addOutputs, Action? addArguments = null) + { + var outputs = new FFMpegMultiOutputOptions(); + addOutputs(outputs); + return ToProcessor(new OutputTeeArgument(outputs), addArguments); + } + + public FFMpegArgumentProcessor MultiOutput(Action addOutputs) + { + var args = new FFMpegMultiOutputOptions(); + addOutputs(args); + Arguments.AddRange(args.Arguments); + return new FFMpegArgumentProcessor(this); + } + internal void Pre() { foreach (var argument in Arguments.OfType()) diff --git a/FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs b/FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs new file mode 100644 index 0000000..594413b --- /dev/null +++ b/FFMpegCore/FFMpeg/FFMpegMultiOutputOptions.cs @@ -0,0 +1,29 @@ +using FFMpegCore.Arguments; +using FFMpegCore.Pipes; + +namespace FFMpegCore +{ + public class FFMpegMultiOutputOptions + { + internal readonly List Outputs = new(); + + public IEnumerable Arguments => Outputs.SelectMany(o => o.Arguments); + + public FFMpegMultiOutputOptions OutputToFile(string file, bool overwrite = true, Action? addArguments = null) => AddOutput(new OutputArgument(file, overwrite), addArguments); + + public FFMpegMultiOutputOptions OutputToUrl(string uri, Action? addArguments = null) => AddOutput(new OutputUrlArgument(uri), addArguments); + + public FFMpegMultiOutputOptions OutputToUrl(Uri uri, Action? addArguments = null) => AddOutput(new OutputUrlArgument(uri.ToString()), addArguments); + + public FFMpegMultiOutputOptions OutputToPipe(IPipeSink reader, Action? addArguments = null) => AddOutput(new OutputPipeArgument(reader), addArguments); + + public FFMpegMultiOutputOptions AddOutput(IOutputArgument argument, Action? addArguments) + { + var args = new FFMpegArgumentOptions(); + addArguments?.Invoke(args); + args.Arguments.Add(argument); + Outputs.Add(args); + return this; + } + } +} From b31c8da7ae218e3d6fb6f03f4ae210a1b0948bef Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 5 Oct 2023 08:58:50 +0200 Subject: [PATCH 26/30] Fix tags container null ref exception --- FFMpegCore/FFProbe/FFProbeAnalysis.cs | 6 +++--- FFMpegCore/FFProbe/MediaFormat.cs | 2 +- FFMpegCore/FFProbe/MediaStream.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index b053d98..0b32da7 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -87,7 +87,7 @@ public class FFProbeStream : ITagsContainer, IDispositionContainer public Dictionary Disposition { get; set; } = null!; [JsonPropertyName("tags")] - public Dictionary Tags { get; set; } = null!; + public Dictionary? Tags { get; set; } [JsonPropertyName("side_data_list")] public List> SideData { get; set; } = null!; @@ -126,7 +126,7 @@ public class Format : ITagsContainer public int ProbeScore { get; set; } [JsonPropertyName("tags")] - public Dictionary Tags { get; set; } = null!; + public Dictionary? Tags { get; set; } } public interface IDispositionContainer @@ -136,7 +136,7 @@ public interface IDispositionContainer public interface ITagsContainer { - Dictionary Tags { get; set; } + Dictionary? Tags { get; set; } } public static class TagExtensions diff --git a/FFMpegCore/FFProbe/MediaFormat.cs b/FFMpegCore/FFProbe/MediaFormat.cs index c588165..7269a95 100644 --- a/FFMpegCore/FFProbe/MediaFormat.cs +++ b/FFMpegCore/FFProbe/MediaFormat.cs @@ -1,6 +1,6 @@ namespace FFMpegCore { - public class MediaFormat + public class MediaFormat : ITagsContainer { public TimeSpan Duration { get; set; } public TimeSpan StartTime { get; set; } diff --git a/FFMpegCore/FFProbe/MediaStream.cs b/FFMpegCore/FFProbe/MediaStream.cs index 008390e..48d1f38 100644 --- a/FFMpegCore/FFProbe/MediaStream.cs +++ b/FFMpegCore/FFProbe/MediaStream.cs @@ -2,7 +2,7 @@ namespace FFMpegCore { - public abstract class MediaStream + public abstract class MediaStream : ITagsContainer { public int Index { get; set; } public string CodecName { get; set; } = null!; From 5fbe71bc39d1c92f1112eb3287981f5d97701cfd Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 5 Oct 2023 08:58:57 +0200 Subject: [PATCH 27/30] Update dependencies --- .../FFMpegCore.Extensions.SkiaSharp.csproj | 4 ++-- FFMpegCore.Test/FFMpegCore.Test.csproj | 14 +++++++------- FFMpegCore/FFMpegCore.csproj | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/FFMpegCore.Extensions.SkiaSharp/FFMpegCore.Extensions.SkiaSharp.csproj b/FFMpegCore.Extensions.SkiaSharp/FFMpegCore.Extensions.SkiaSharp.csproj index d15a7bd..87710cc 100644 --- a/FFMpegCore.Extensions.SkiaSharp/FFMpegCore.Extensions.SkiaSharp.csproj +++ b/FFMpegCore.Extensions.SkiaSharp/FFMpegCore.Extensions.SkiaSharp.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/FFMpegCore.Test/FFMpegCore.Test.csproj b/FFMpegCore.Test/FFMpegCore.Test.csproj index b78af1b..7c4b888 100644 --- a/FFMpegCore.Test/FFMpegCore.Test.csproj +++ b/FFMpegCore.Test/FFMpegCore.Test.csproj @@ -8,19 +8,19 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 2af7f16..ed3b71c 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -18,7 +18,7 @@ - + From 55b1946976665d1581b542524110633dbbb242c5 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 5 Oct 2023 09:14:47 +0200 Subject: [PATCH 28/30] Update FFProbeTests.cs --- FFMpegCore.Test/FFProbeTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 9da819a..ff7aafc 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -46,7 +46,7 @@ public async Task PacketAnalysis_Async() var packets = packetAnalysis.Packets; Assert.AreEqual(96, packets.Count); Assert.IsTrue(packets.All(f => f.CodecType == "video")); - Assert.AreEqual("K_", packets[0].Flags); + Assert.IsTrue(packets[0].Flags.StartsWith("K_")); Assert.AreEqual(1362, packets.Last().Size); } @@ -57,7 +57,7 @@ public void PacketAnalysis_Sync() Assert.AreEqual(96, packets.Count); Assert.IsTrue(packets.All(f => f.CodecType == "video")); - Assert.AreEqual("K_", packets[0].Flags); + Assert.IsTrue(packets[0].Flags.StartsWith("K_")); Assert.AreEqual(1362, packets.Last().Size); } @@ -70,7 +70,7 @@ public void PacketAnalysisAudioVideo_Sync() var actual = packets.Select(f => f.CodecType).Distinct().ToList(); var expected = new List { "audio", "video" }; CollectionAssert.AreEquivalent(expected, actual); - Assert.IsTrue(packets.Where(t => t.CodecType == "audio").All(f => f.Flags == "K_")); + Assert.IsTrue(packets.Where(t => t.CodecType == "audio").All(f => f.Flags.StartsWith("K_"))); Assert.AreEqual(75, packets.Count(t => t.CodecType == "video")); Assert.AreEqual(141, packets.Count(t => t.CodecType == "audio")); } From ed30b146871df5bade326d6306a058dac0f1ae5b Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 5 Oct 2023 09:24:44 +0200 Subject: [PATCH 29/30] Align with main branch --- FFMpegCore/FFProbe/FFProbeAnalysis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index 09a1cd9..1966242 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -153,7 +153,7 @@ public class Chapter : ITagsContainer public string EndTime { get; set; } = null!; [JsonPropertyName("tags")] - public Dictionary Tags { get; set; } = null!; + public Dictionary? Tags { get; set; } } public interface IDispositionContainer From df123bb1912fa9e089a8835c9b69bc3ea013b16d Mon Sep 17 00:00:00 2001 From: Vortex Date: Mon, 16 Oct 2023 03:20:31 +0200 Subject: [PATCH 30/30] Fix: Changed "Chapter" Modell since "Id", "Start" and "End" returned by ffprobe can contain values larger than Int32.MaxValue --- FFMpegCore/FFProbe/FFProbeAnalysis.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index 1966242..e88f461 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -135,19 +135,19 @@ public class Format : ITagsContainer public class Chapter : ITagsContainer { [JsonPropertyName("id")] - public int Id { get; set; } + public long Id { get; set; } [JsonPropertyName("time_base")] public string TimeBase { get; set; } = null!; [JsonPropertyName("start")] - public int Start { get; set; } + public long Start { get; set; } [JsonPropertyName("start_time")] public string StartTime { get; set; } = null!; [JsonPropertyName("end")] - public int End { get; set; } + public long End { get; set; } [JsonPropertyName("end_time")] public string EndTime { get; set; } = null!;