From a49e519672599b3a152db2050bef1f1e783f735e Mon Sep 17 00:00:00 2001 From: AndreasS Date: Mon, 21 Jan 2019 23:17:56 +0200 Subject: [PATCH 1/5] Update CommandBuilder.cs --- MediaToolkit src/MediaToolkit/CommandBuilder.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MediaToolkit src/MediaToolkit/CommandBuilder.cs b/MediaToolkit src/MediaToolkit/CommandBuilder.cs index 127936e..42041df 100644 --- a/MediaToolkit src/MediaToolkit/CommandBuilder.cs +++ b/MediaToolkit src/MediaToolkit/CommandBuilder.cs @@ -79,6 +79,10 @@ private static string Convert(MediaFile inputFile, MediaFile outputFile, Convers // Audio sample rate if (conversionOptions.AudioSampleRate != AudioSampleRate.Default) commandBuilder.AppendFormat(" -ar {0} ", conversionOptions.AudioSampleRate.Remove("Hz")); + + //Audio downmix + if (conversionOptions.AudioDownmix) + commandBuilder.AppendFormat(" -ac 1 "); // Maximum video duration if (conversionOptions.MaxVideoDuration != null) From 1cc8108015b7705d19b1fa7aafe81af31dced92a Mon Sep 17 00:00:00 2001 From: AndreasS Date: Mon, 21 Jan 2019 23:18:35 +0200 Subject: [PATCH 2/5] Update ConversionOptions.cs --- MediaToolkit src/MediaToolkit/Options/ConversionOptions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MediaToolkit src/MediaToolkit/Options/ConversionOptions.cs b/MediaToolkit src/MediaToolkit/Options/ConversionOptions.cs index 5b85d48..f79fae6 100644 --- a/MediaToolkit src/MediaToolkit/Options/ConversionOptions.cs +++ b/MediaToolkit src/MediaToolkit/Options/ConversionOptions.cs @@ -38,6 +38,11 @@ public void CutMedia(TimeSpan seekToPosition, TimeSpan length) /// Audio sample rate /// public AudioSampleRate AudioSampleRate = AudioSampleRate.Default; + + /// + /// Audio sample rate + /// + public bool AudioDownmix = false; /// /// The maximum duration @@ -101,4 +106,4 @@ public void CutMedia(TimeSpan seekToPosition, TimeSpan length) public bool BaselineProfile { get; set; } } -} \ No newline at end of file +} From e0b924e31f8c14e2947933c8df08ca84cb90d033 Mon Sep 17 00:00:00 2001 From: AndreasS Date: Tue, 22 Jan 2019 00:29:08 +0200 Subject: [PATCH 3/5] Update FFmpegTask.cs --- MediaToolkit src/MediaToolkit/FFmpegTask.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MediaToolkit src/MediaToolkit/FFmpegTask.cs b/MediaToolkit src/MediaToolkit/FFmpegTask.cs index 2e858d6..12d98f1 100644 --- a/MediaToolkit src/MediaToolkit/FFmpegTask.cs +++ b/MediaToolkit src/MediaToolkit/FFmpegTask.cs @@ -11,6 +11,9 @@ internal enum FFmpegTask GetMetaData, /// An enum constant representing the get thumbnail option. - GetThumbnail + GetThumbnail, + + /// An enum constant representing the extract frames option. + ExtractFrames } -} \ No newline at end of file +} From f024f35612d5bd671689664ef6aec828450d7cf5 Mon Sep 17 00:00:00 2001 From: AndreasS Date: Tue, 22 Jan 2019 00:31:33 +0200 Subject: [PATCH 4/5] Update CommandBuilder.cs --- MediaToolkit src/MediaToolkit/CommandBuilder.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MediaToolkit src/MediaToolkit/CommandBuilder.cs b/MediaToolkit src/MediaToolkit/CommandBuilder.cs index 42041df..f4d5118 100644 --- a/MediaToolkit src/MediaToolkit/CommandBuilder.cs +++ b/MediaToolkit src/MediaToolkit/CommandBuilder.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using System.Text; +using System.IO; namespace MediaToolkit { @@ -21,6 +22,8 @@ internal static string Serialize(EngineParameters engineParameters) case FFmpegTask.GetThumbnail: return GetThumbnail(engineParameters.InputFile, engineParameters.OutputFile, engineParameters.ConversionOptions); + case FFmpegTask.ExtractFrames: + return ExtractFrames(engineParameters.InputFile); default: throw new ArgumentOutOfRangeException(); } @@ -42,6 +45,16 @@ private static string GetThumbnail(MediaFile inputFile, MediaFile outputFile, Co return commandBuilder.AppendFormat(" \"{0}\" ", outputFile.Filename).ToString(); } + + private static string ExtractFrames(MediaFile inputFile) + { + var commandBuilder = new StringBuilder(); + + commandBuilder.AppendFormat(" -i \"{0}\" ", inputFile.Filename); + + return commandBuilder.AppendFormat(@" -r 1/1 " + Path.GetDirectoryName(inputFile.Filename) + "\\" + "frame%05d.jpg ").ToString(); + + } private static string Convert(MediaFile inputFile, MediaFile outputFile, ConversionOptions conversionOptions) { From a9763a973e3c156cbb449fd41797be4c25665c0a Mon Sep 17 00:00:00 2001 From: AndreasS Date: Tue, 22 Jan 2019 00:32:09 +0200 Subject: [PATCH 5/5] Update Engine.cs --- MediaToolkit src/MediaToolkit/Engine.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MediaToolkit src/MediaToolkit/Engine.cs b/MediaToolkit src/MediaToolkit/Engine.cs index 6d623aa..fb2a56b 100644 --- a/MediaToolkit src/MediaToolkit/Engine.cs +++ b/MediaToolkit src/MediaToolkit/Engine.cs @@ -119,6 +119,20 @@ public void GetThumbnail(MediaFile inputFile, MediaFile outputFile, ConversionOp this.FFmpegEngine(engineParams); } + /// ------------------------------------------------------------------------------------------------- + /// Extracts all frames from a video. + /// Video file. + public void ExtractFrames(MediaFile inputFile) + { + EngineParameters engineParams = new EngineParameters + { + InputFile = inputFile, + Task = FFmpegTask.ExtractFrames + }; + + this.FFmpegEngine(engineParams); + } + #region Private method - Helpers private void FFmpegEngine(EngineParameters engineParameters) @@ -303,4 +317,4 @@ private void StartFFmpegProcess(EngineParameters engineParameters) } } } -} \ No newline at end of file +}