From b11be87a45aadb901e46897a795f27d9637d378c Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 12 Feb 2020 20:45:16 +0100 Subject: [PATCH] More cleanup Former-commit-id: ecf7a711f4ced0480fa672584973f707872e337c --- FFMpegCore.Test/ArgumentBuilderTest.cs | 6 +++--- .../FFMPEG/Argument/ArgumentStringifier.cs | 6 +++--- FFMpegCore/FFMPEG/FFMpeg.cs | 18 ++++++++---------- FFMpegCore/FFMpegCore.csproj | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 68df940..9dd1b9a 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -53,7 +53,7 @@ public void Builder_BuildString_Scale() public void Builder_BuildString_AudioCodec() { var str = GetArgumentsString(new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal)); - Assert.AreEqual(str, "-i \"input.mp4\" -codec:a aac -b:a 128k -strict experimental \"output.mp4\""); + Assert.AreEqual(str, "-i \"input.mp4\" -c:a aac -b:a 128k \"output.mp4\""); } [TestMethod] @@ -204,7 +204,7 @@ public void Builder_BuildString_Codec() { var str = GetArgumentsString(new VideoCodecArgument(VideoCodec.LibX264)); - Assert.AreEqual(str, "-i \"input.mp4\" -codec:v libx264 -pix_fmt yuv420p \"output.mp4\""); + Assert.AreEqual(str, "-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p \"output.mp4\""); } [TestMethod] @@ -212,7 +212,7 @@ public void Builder_BuildString_Codec_Override() { var str = GetArgumentsString(new VideoCodecArgument(VideoCodec.LibX264), new OverrideArgument()); - Assert.AreEqual(str, "-i \"input.mp4\" -codec:v libx264 -pix_fmt yuv420p -y \"output.mp4\""); + Assert.AreEqual(str, "-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p -y \"output.mp4\""); } [TestMethod] diff --git a/FFMpegCore/FFMPEG/Argument/ArgumentStringifier.cs b/FFMpegCore/FFMPEG/Argument/ArgumentStringifier.cs index 0a723ef..ee11c03 100644 --- a/FFMpegCore/FFMPEG/Argument/ArgumentStringifier.cs +++ b/FFMpegCore/FFMPEG/Argument/ArgumentStringifier.cs @@ -24,7 +24,7 @@ internal static string Audio(AudioCodec codec, int bitrate) internal static string Audio(AudioCodec codec) { - return $"-codec:a {codec.ToString().ToLower()} "; + return $"-c:a {codec.ToString().ToLower()} "; } internal static string Audio(AudioQuality bitrate) @@ -34,12 +34,12 @@ internal static string Audio(AudioQuality bitrate) internal static string Audio(int bitrate) { - return $"-b:a {bitrate}k -strict experimental "; + return $"-b:a {bitrate}k "; } internal static string Video(VideoCodec codec, int bitrate = 0) { - var video = $"-codec:v {codec.ToString().ToLower()} -pix_fmt yuv420p "; + var video = $"-c:v {codec.ToString().ToLower()} -pix_fmt yuv420p "; if (bitrate > 0) { diff --git a/FFMpegCore/FFMPEG/FFMpeg.cs b/FFMpegCore/FFMPEG/FFMpeg.cs index 5fe7689..b5b49db 100644 --- a/FFMpegCore/FFMPEG/FFMpeg.cs +++ b/FFMpegCore/FFMPEG/FFMpeg.cs @@ -99,11 +99,9 @@ public Bitmap Snapshot(VideoInfo source, FileInfo output, Size? size = null, Tim Bitmap result; using (var bmp = (Bitmap) Image.FromFile(output.FullName)) { - using (var ms = new MemoryStream()) - { - bmp.Save(ms, ImageFormat.Png); - result = new Bitmap(ms); - } + using var ms = new MemoryStream(); + bmp.Save(ms, ImageFormat.Png); + result = new Bitmap(ms); } if (output.Exists && !persistSnapshotOnFileSystem) @@ -499,13 +497,13 @@ private bool RunProcess(ArgumentContainer container, FileInfo output) Process.Close(); if (File.Exists(output.FullName)) - using (var file = File.Open(output.FullName, FileMode.Open)) + { + using var file = File.Open(output.FullName, FileMode.Open); + if (file.Length == 0) { - if (file.Length == 0) - { - throw new FFMpegException(FFMpegExceptionType.Process, _errorOutput); - } + throw new FFMpegException(FFMpegExceptionType.Process, _errorOutput); } + } else { throw new FFMpegException(FFMpegExceptionType.Process, _errorOutput); diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index a72cabc..f786256 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -129,7 +129,7 @@ - +