[FFmpeg-user] -vf pad and -aspect problem

Andrew Pettican andrew at designwildwest.com
Wed May 11 11:42:31 CEST 2011


Hi,

I'm having a little trouble with the -vf pad and -aspect options.

The basic story is that I have a source video (176x144, approx 5:4) which should be scaled up to 384x216 (16:9) adding pillerbox padding where necessary. I know scaling up should be avoided, but this is for a website which expects all videos to have identical dimensions.

On my local PC I use the following command to achieve this, and it appears to work fine:
c:\ffmpeg\bin\ffmpeg -i c:\ffmpeg\original.mp4 -vcodec libvpx -acodec libvorbis -ac 2 -ar 22050 -ab 64k -b 400k -r 15 -f webm -y -s 264x216 -aspect 16:9 -vf pad=384:216:60:0:red c:\ffmpeg\test-output-aspect.16.9.webm

i.e. scale from 176x144 to 264x216 then pad to 384x216 (60px each side)

The returned video is 384x216 and in a 16:9 aspect ratio:
Stream #0.0(eng): Video: libvpx, yuv420p, 384x216 [PAR 1:1 DAR 16:9], q=2-31, 400 kb/s, 1k tbn, 15 tbc

------

The problem lies with my web server where this will actually be running when live. The same command appears to stretch the video, making it extra wide.

The returned video is still 384x216 but it no longer has a 1:1 pixel aspect ratio so the video ends up with a 256:99 (16:6.19) aspect ratio:
Stream #0.0(eng): Video: libvpx, yuv420p, 384x216 [PAR 16:11 DAR 256:99], q=2-31, 400 kb/s, 1k tbn, 15 tbc

Examining frames from both of these videos in VLC:
- the PC has 60px of padding, 264px of image, and 60px of padding = 384px total width. This is what I expect.
- the server has approx 87px of padding, 384px of image, and 87px of padding = 558px total width
- Both videos are exactly 216px high as expected.

It seems to me that the server applies the 16:9 aspect and ignores the padding that was applied. This stretches the 5:4 video to a 16:9 aspect and also stretches the 60px of padding to 87px on either side.

I've also tried running the commands on both machines without the -aspect option. In this case both machines generate the same size video:
- Stream #0.0(eng): Video: libvpx, yuv420p, 384x216 [PAR 193:176 DAR 193:99], q=2-31, 400 kb/s, 1k tbn, 15 tbc (pc)
- Stream #0.0(eng): Video: libvpx, yuv420p, 384x216 [PAR 193:176 DAR 193:99], q=2-31, 400 kb/s, 1k tbn, 15 tbc (server)

Note:
- The version of ffmpeg on my PC was obtained from http://hawkeye.arrozcru.org/ - "FFmpeg git-95f163b 32-bit Static (Latest)"
- The version of ffmpeg on my server was compiled from source by my server administrator.

Any help/suggestions you have would be greatly appreciated.

Is there something wrong with my command, or anything I can do to make it clear to ffmpeg what I want?

The full ffmpeg output for each command is as follows:

PC:
----------------------------------
C:\Users\Andrew>c:\ffmpeg\bin\ffmpeg -i c:\ffmpeg\original.mp4 -vcodec libvpx -acodec libvorbis -ac 2 -ar 22050 -ab 64k -b 400k -r 15 -f webm -y -s 264x216 -aspect 16:9 -vf pad=384:216:60:0:red c:\ffmpeg\test-output-aspect.16.9.webm
ffmpeg version git-N-29638-g95f163b, Copyright (c) 2000-2011 the FFmpeg developers
  built on May  6 2011 12:50:01 with gcc 4.5.3
  configuration: --enable-gpl --enable-version3 --enable-memalign-hack --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib --pkg-config=pkg-config
  libavutil    51.  2. 1 / 51.  2. 1
  libavcodec   53.  3. 0 / 53.  3. 0
  libavformat  53.  0. 3 / 53.  0. 3
  libavdevice  53.  0. 0 / 53.  0. 0
  libavfilter   2.  4. 0 /  2.  4. 0
  libswscale    0. 14. 0 /  0. 14. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'c:\ffmpeg\original.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2010-04-09 18:16:16
    encoder         : mp4creator 1.4.4
  Duration: 00:02:33.93, start: 0.000000, bitrate: 197 kb/s
    Stream #0.0(eng): Video: mpeg4, yuv420p, 176x144 [PAR 193:176 DAR 193:144], 133 kb/s, 15 fps, 15 tbr, 90k tbn, 15 tbc
    Metadata:
      creation_time   : 2010-04-09 18:16:16
    Stream #0.1(eng): Audio: aac, 11025 Hz, stereo, s16, 63 kb/s
    Metadata:
      creation_time   : 2010-04-09 18:16:17
[buffer @ 029964E0] w:176 h:144 pixfmt:yuv420p
[scale @ 029968A0] w:176 h:144 fmt:yuv420p -> w:264 h:216 fmt:yuv420p flags:0x4
[pad @ 02996D00] w:264 h:216 -> w:384 h:216 x:60 y:0 color:0x515AF0FF[yuva]
[libvpx @ 0029F6C0] v0.9.6
Output #0, webm, to 'c:\ffmpeg\test-output-aspect.16.9.webm':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2010-04-09 18:16:16
    encoder         : Lavf53.0.3
    Stream #0.0(eng): Video: libvpx, yuv420p, 384x216 [PAR 1:1 DAR 16:9], q=2-31, 400 kb/s, 1k tbn, 15 tbc
    Metadata:
      creation_time   : 2010-04-09 18:16:16
    Stream #0.1(eng): Audio: libvorbis, 22050 Hz, stereo, s16, 64 kb/s
    Metadata:
      creation_time   : 2010-04-09 18:16:17
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 2309 fps= 42 q=0.0 Lsize=    8308kB time=153.72 bitrate= 442.8kbits/s

video:7515kB audio:726kB global headers:4kB muxing overhead 0.772855%


Server:
----------------------------------
root at WildWildWest [~]> nice -n 19 /usr/bin/ffmpeg -i /path/to/video/original.mp4 -vcodec libvpx -acodec libvorbis -ac 2 -ar 22050 -ab 64k -b 400k -r 15 -f webm -y -s 264x216 -aspect 16:9 -vf pad=384:216:60:0:red /path/to/video/test-output-aspect.16.9.webm
FFmpeg version SVN-r26400, Copyright (c) 2000-2011 the FFmpeg developers
  built on May 10 2011 16:39:45 with gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
  configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -m64 -mtune=generic -fPIC' --enable-avfilter --enable-libdirac --enable-libfaac --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvorbis --enable-libvpx --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
  libavutil     50.36. 0 / 50.36. 0
  libavcore      0.16. 1 /  0.16. 1
  libavcodec    52.108. 0 / 52.108. 0
  libavformat   52.93. 0 / 52.93. 0
  libavdevice   52. 2. 3 / 52. 2. 3
  libavfilter    1.74. 0 /  1.74. 0
  libswscale     0.12. 0 /  0.12. 0
  libpostproc   51. 2. 0 / 51. 2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/path/to/video/original.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2010-04-09 18:16:16
    encoder         : mp4creator 1.4.4
  Duration: 00:02:33.93, start: 0.000000, bitrate: 197 kb/s
    Stream #0.0(eng): Video: mpeg4, yuv420p, 176x144 [PAR 193:176 DAR 193:144], 133 kb/s, 15 fps, 15 tbr, 90k tbn, 15 tbc
    Metadata:
      creation_time   : 2010-04-09 18:16:16
    Stream #0.1(eng): Audio: aac, 11025 Hz, stereo, s16, 63 kb/s
    Metadata:
      creation_time   : 2010-04-09 18:16:17
[buffer @ 0xeb1e1b0] w:176 h:144 pixfmt:yuv420p
[scale @ 0xeb1e580] w:176 h:144 fmt:yuv420p -> w:264 h:216 fmt:yuv420p flags:0xa0000004
[pad @ 0xeb1e8b0] w:264 h:216 -> w:384 h:216 x:60 y:0 color:0x515AF0FF[yuva]
[libvpx @ 0xeb1aa90] v0.9.6
Output #0, webm, to '/path/to/video/test-output-aspect.16.9.webm':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2010-04-09 18:16:16
    encoder         : Lavf52.93.0
    Stream #0.0(eng): Video: libvpx, yuv420p, 384x216 [PAR 16:11 DAR 256:99], q=2-31, 400 kb/s, 1k tbn, 15 tbc
    Metadata:
      creation_time   : 2010-04-09 18:16:16
    Stream #0.1(eng): Audio: libvorbis, 22050 Hz, stereo, s16, 64 kb/s
    Metadata:
      creation_time   : 2010-04-09 18:16:17
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 2309 fps= 60 q=0.0 Lsize=    8327kB time=153.72 bitrate= 443.8kbits/s    
video:7516kB audio:744kB global headers:4kB muxing overhead 0.772233%


More information about the ffmpeg-user mailing list