[FFmpeg-user] WMV to H264 resulting in size change

Benjamin Black benblack86 at gmail.com
Mon Apr 20 17:18:36 CEST 2015


I think there are two separate issues happening here.


When I play the original using WMP the video is given a space of 720x480, but actually it is 640x480 with black space on either side to pad out the video. If I make the video player smaller by width then the padding disappears before the video is resized to keep aspect ratio correct. When I play the video using VLC on my mac then the image is stretched to be 720. The H264 output matches what the original looks like, but without the padding (when played using QT). Please see https://www.dropbox.com/s/t56u2cdsrpp5tlb/sizes.png?dl=0 for a visual comparison (bottom of the stack is the original playing in WMP, next video is the original playing in VLC, and the top video is the output playing in QT).




The second issue is that VLC and QT on my mac display the output differently, with VLC making the video look bigger. I’m guessing that they attempt to handle SAR differently. The solution seems to be to normalize the pixels to be square so we don’t have to depend on the capabilities of the video player. To do this I use -vf 'scale=trunc((iw*sar)/2)*2:trunc(ih/2)*2,setsar=1’. Since I’m using this filter on a load of different videos I'm also making sure the width/height are even and then I’m forcing SAR to be 1:1 as otherwise I sometimes get some crazy ratio (probably due to rounding).




These are the commands I’m using:





ffmpeg -y -i original.wmv -c:v libx264 -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' -profile:v baseline -b:v 3072k -preset medium -c:a libfdk_aac -profile:a aac_low -ac 2 -b:a 128k -r:a 44100 -movflags faststart output.mp4




ffmpeg -y -i original.wmv -c:v libx264 -vf 'scale=trunc((iw*sar)/2)*2:trunc(ih/2)*2,setsar=1' -profile:v baseline -b:v 3072k -preset medium -c:a libfdk_aac -profile:a aac_low -ac 2 -b:a 128k -r:a 44100 -movflags faststart output_normalized.mp4




And here is some probe output (note that the width is different for the two outputs):





original.wmv

[STREAM]

codec_name=wmv3

profile=Main

width=720

height=480

sample_aspect_ratio=8:9

display_aspect_ratio=4:3

pix_fmt=yuv420p

[/STREAM]










output.mp4

[STREAM]

codec_name=h264

profile=Constrained Baseline

width=720

height=480

sample_aspect_ratio=8:9

display_aspect_ratio=4:3

pix_fmt=yuv420p

[/STREAM]







output_normalized.mp4

[STREAM]

codec_name=h264

profile=Constrained Baseline

width=640

height=480

sample_aspect_ratio=1:1

display_aspect_ratio=4:3

pix_fmt=yuv420p

[/STREAM]




Thanks,

Ben


More information about the ffmpeg-user mailing list