Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #19 from vladjerca/fix/conversion_size
Browse files Browse the repository at this point in the history
FFMpeg.Core: Fix resizing issue (width was swapped with height)
  • Loading branch information
vladjerca authored Sep 22, 2018
2 parents cc43430 + 38cffe5 commit 6e7e03d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FFMpegSharp.Tests/VideoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public bool Convert(VideoType type, bool multithreaded = false, VideoSize size =
size != VideoSize.Original &&
outputVideo.Width != input.Width &&
outputVideo.Height != input.Height &&
outputVideo.Width == (int)size
outputVideo.Height == (int)size
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions FFMpegSharp/FFMPEG/Atomic/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ internal static string Input(string template)
return $"-i \"{template}\" ";
}

internal static string Scale(VideoSize size, int height)
internal static string Scale(Size size)
{
return size == VideoSize.Original ? string.Empty : $"-vf scale={(int)size}:{height} ";
return $"-vf scale={size.Width}:{size.Height} ";
}

internal static string Size(Size? size)
Expand Down
16 changes: 13 additions & 3 deletions FFMpegSharp/FFMPEG/FFMpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,25 @@ public VideoInfo Convert(
FFMpegHelper.ConversionSizeExceptionCheck(source);

string args = "";

var scale = (double)source.Height / (int)size;

var height = source.Height * (source.Width / (int)size);
var outputSize = new Size(
(int)(source.Width / scale),
(int)(source.Height / scale)
);

if (outputSize.Width % 2 != 0)
{
outputSize.Width += 1;
}

switch (type)
{
case VideoType.Mp4:
args = Arguments.Input(source) +
Arguments.Threads(multithreaded) +
Arguments.Scale(size, height) +
Arguments.Scale(outputSize) +
Arguments.Video(VideoCodec.LibX264, 2400) +
Arguments.Speed(speed) +
Arguments.Audio(AudioCodec.Aac, audioQuality) +
Expand All @@ -154,7 +164,7 @@ public VideoInfo Convert(
case VideoType.Ogv:
args = Arguments.Input(source) +
Arguments.Threads(multithreaded) +
Arguments.Scale(size, height) +
Arguments.Scale(outputSize) +
Arguments.Video(VideoCodec.LibTheora, 2400) +
Arguments.Speed(16) +
Arguments.Audio(AudioCodec.LibVorbis, audioQuality) +
Expand Down
2 changes: 1 addition & 1 deletion FFMpegSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 6e7e03d

Please sign in to comment.