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

Commit 6e7e03d

Browse files
authored
Merge pull request #19 from vladjerca/fix/conversion_size
FFMpeg.Core: Fix resizing issue (width was swapped with height)
2 parents cc43430 + 38cffe5 commit 6e7e03d

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

FFMpegSharp.Tests/VideoTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public bool Convert(VideoType type, bool multithreaded = false, VideoSize size =
3737
size != VideoSize.Original &&
3838
outputVideo.Width != input.Width &&
3939
outputVideo.Height != input.Height &&
40-
outputVideo.Width == (int)size
40+
outputVideo.Height == (int)size
4141
)
4242
);
4343
}

FFMpegSharp/FFMPEG/Atomic/Arguments.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ internal static string Input(string template)
8282
return $"-i \"{template}\" ";
8383
}
8484

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

9090
internal static string Size(Size? size)

FFMpegSharp/FFMPEG/FFMpeg.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,25 @@ public VideoInfo Convert(
137137
FFMpegHelper.ConversionSizeExceptionCheck(source);
138138

139139
string args = "";
140+
141+
var scale = (double)source.Height / (int)size;
140142

141-
var height = source.Height * (source.Width / (int)size);
143+
var outputSize = new Size(
144+
(int)(source.Width / scale),
145+
(int)(source.Height / scale)
146+
);
147+
148+
if (outputSize.Width % 2 != 0)
149+
{
150+
outputSize.Width += 1;
151+
}
142152

143153
switch (type)
144154
{
145155
case VideoType.Mp4:
146156
args = Arguments.Input(source) +
147157
Arguments.Threads(multithreaded) +
148-
Arguments.Scale(size, height) +
158+
Arguments.Scale(outputSize) +
149159
Arguments.Video(VideoCodec.LibX264, 2400) +
150160
Arguments.Speed(speed) +
151161
Arguments.Audio(AudioCodec.Aac, audioQuality) +
@@ -154,7 +164,7 @@ public VideoInfo Convert(
154164
case VideoType.Ogv:
155165
args = Arguments.Input(source) +
156166
Arguments.Threads(multithreaded) +
157-
Arguments.Scale(size, height) +
167+
Arguments.Scale(outputSize) +
158168
Arguments.Video(VideoCodec.LibTheora, 2400) +
159169
Arguments.Speed(16) +
160170
Arguments.Audio(AudioCodec.LibVorbis, audioQuality) +

FFMpegSharp/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
// by using the '*' as shown below:
3636
// [assembly: AssemblyVersion("1.0.*")]
3737

38-
[assembly: AssemblyVersion("2.0.0.0")]
38+
[assembly: AssemblyVersion("2.0.1.0")]
3939
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)