From c4232b7ca0640ad811f6d29b4e535fccc146b3b5 Mon Sep 17 00:00:00 2001 From: Brett Baker Date: Fri, 1 Nov 2024 09:13:29 -0400 Subject: [PATCH 1/4] Added Copy option to Audio --- FFMpegCore/FFMpeg/Enums/Enums.cs | 2 ++ FFMpegCore/FFMpegCore.csproj | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/Enums/Enums.cs b/FFMpegCore/FFMpeg/Enums/Enums.cs index 4974b448..0155743c 100644 --- a/FFMpegCore/FFMpeg/Enums/Enums.cs +++ b/FFMpegCore/FFMpeg/Enums/Enums.cs @@ -27,6 +27,8 @@ public static class AudioCodec public static Codec Ac3 => FFMpeg.GetCodec("ac3"); public static Codec Eac3 => FFMpeg.GetCodec("eac3"); public static Codec LibMp3Lame => FFMpeg.GetCodec("libmp3lame"); + public static Codec Copy => new Codec("copy", CodecType.Audio); + } public static class VideoType diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index ed3b71c8..cf17d85c 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -18,7 +18,7 @@ - + From 72eddfca6db03939b6da96be2fd66a0d843f4809 Mon Sep 17 00:00:00 2001 From: Brett Baker Date: Sat, 2 Nov 2024 07:34:21 -0400 Subject: [PATCH 2/4] Add CropArgument Add the option to crop the video to a given size. --- FFMpegCore/FFMpeg/Arguments/CropArgument.cs | 22 +++++++++++++++++++++ FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 FFMpegCore/FFMpeg/Arguments/CropArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/CropArgument.cs b/FFMpegCore/FFMpeg/Arguments/CropArgument.cs new file mode 100644 index 00000000..51ac0618 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/CropArgument.cs @@ -0,0 +1,22 @@ +using System.Drawing; + +namespace FFMpegCore.Arguments +{ + public class CropArgument : IArgument + { + public readonly Size? Size; + public readonly int Top; + public readonly int Left; + + public CropArgument(Size? size, int top, int left) + { + Size = size; + Top = top; + Left = left; + } + + public CropArgument(int width, int height, int top, int left) : this(new Size(width, height), top, left) { } + + public string Text => Size == null ? string.Empty : $"-vf crop={Size.Value.Width}:{Size.Value.Height}:{Left}:{Top}"; + } +} diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index 6a6586c4..941c1c27 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -16,7 +16,10 @@ internal FFMpegArgumentOptions() { } public FFMpegArgumentOptions WithVariableBitrate(int vbr) => WithArgument(new VariableBitRateArgument(vbr)); public FFMpegArgumentOptions Resize(int width, int height) => WithArgument(new SizeArgument(width, height)); public FFMpegArgumentOptions Resize(Size? size) => WithArgument(new SizeArgument(size)); - + public FFMpegArgumentOptions Crop(Size? size, int left, int top) => WithArgument(new CropArgument(size, top, left)); + public FFMpegArgumentOptions Crop(int width, int height, int left, int top) => WithArgument(new CropArgument(new Size(width, height), top, left)); + public FFMpegArgumentOptions Crop(Size? size) => WithArgument(new CropArgument(size, 0, 0)); + public FFMpegArgumentOptions Crop(int width, int height) => WithArgument(new CropArgument(new Size(width, height), 0, 0)); public FFMpegArgumentOptions WithBitStreamFilter(Channel channel, Filter filter) => WithArgument(new BitStreamFilterArgument(channel, filter)); public FFMpegArgumentOptions WithConstantRateFactor(int crf) => WithArgument(new ConstantRateFactorArgument(crf)); public FFMpegArgumentOptions CopyChannel(Channel channel = Channel.Both) => WithArgument(new CopyArgument(channel)); From ff42378834422244e3076a6a7cc791cc548d1cc5 Mon Sep 17 00:00:00 2001 From: Brett Baker Date: Wed, 13 Nov 2024 08:45:00 -0500 Subject: [PATCH 3/4] null check on title to not fail Media Analysis If the title is missing from the analysis metadata, the analysis fails. Added null check and default value of "TitleValueNotSet". --- FFMpegCore/FFProbe/MediaAnalysis.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 887baeba..af37cf2c 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -30,9 +30,12 @@ private MediaFormat ParseFormat(Format analysisFormat) }; } + private string GetValue(string tagName, Dictionary? tags, string defaultValue) => + tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue; + private ChapterData ParseChapter(Chapter analysisChapter) { - var title = analysisChapter.Tags.FirstOrDefault(t => t.Key == "title").Value; + var title = GetValue("title", analysisChapter.Tags, "TitleValueNotSet"); var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime); var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime); From 5d654af5f8c288e54aa96c75a6c7d079ea6fac1c Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 4 Dec 2024 21:51:43 +0200 Subject: [PATCH 4/4] dotnet format --- FFMpegCore/FFMpeg/Arguments/CropArgument.cs | 2 +- FFMpegCore/FFProbe/MediaAnalysis.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/CropArgument.cs b/FFMpegCore/FFMpeg/Arguments/CropArgument.cs index 51ac0618..4fe10d64 100644 --- a/FFMpegCore/FFMpeg/Arguments/CropArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/CropArgument.cs @@ -6,7 +6,7 @@ public class CropArgument : IArgument { public readonly Size? Size; public readonly int Top; - public readonly int Left; + public readonly int Left; public CropArgument(Size? size, int top, int left) { diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index ab289eb8..435f719a 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -31,7 +31,7 @@ private MediaFormat ParseFormat(Format analysisFormat) } private string GetValue(string tagName, Dictionary? tags, string defaultValue) => - tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue; + tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue; private ChapterData ParseChapter(Chapter analysisChapter) {