10

I am trying the padding option using ffmpeg, but I am getting an error.

I am following this tutorial. Here's the error:

ffmpeg version git-2013-11-13-129af66 Copyright (c) 2000-2013 the FFmpeg developers
built on Nov 13 2013 16:40:26 with gcc 4.4.3 (GCC)
configuration: --arch=arm --target-os=linux --enable-cross-compile --cross-prefix=/Users/sunitha/Downloads/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi- --prefix=../build --sysroot=/Users/sunitha/Downloads/android-ndk/platforms/android-9/arch-arm --extra-cflags=' -I/Users/sunitha/Downloads/android-ndk/platforms/android-9/arch-arm/usr/include -I/Users/sunitha/Downloads/full_ffmpeg/ffmpeg-android/libmp3lame/include -DANDROID -marm -march=armv6 ' --extra-ldflags=' -L/Users/sunitha/Downloads/android-ndk/platforms/android-9/arch-arm/usr/lib -L/Users/sunitha/Downloads/full_ffmpeg/ffmpeg-android/libmp3lame/lib' --disable-debug --enable-libmp3lame --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avfilter --enable-decoders --enable-demuxers --enable-encoders --enable-filters --enable-indevs --enable-network --enable-parsers --enable-protocols --enable-swscale --enable-gpl --enable-nonfree
libavutil      52. 39.100 / 52. 39.100  
libavcodec     55. 18.102 / 55. 18.102  
libavformat    55. 12.102 / 55. 12.102  
libavdevice    55.  3.100 / 55.  3.100  
libavfilter     3. 80.100 /  3. 80.100  
libswscale      2.  3.100 /  2.  3.100  
libswresample   0. 17.102 /  0. 17.102  
libpostproc    52.  3.100 / 52.  3.100
Unrecognized option 'padtop 120'.
Error splitting the argument list: Option not found
1

2 Answers 2

27

Try it this way instead:

 ffmpeg -i input.avi -vf "pad=width=640:height=480:x=0:y=120:color=black" output.avi  

The video filter syntax is the new way to use padding. Here the video output width and height are 640x480 and the image is placed 120 pixels from top, 0 pixels from left. To work out your exact dimensions, just apply the same principles.

See the pad video filter documentation for more details.

4
  • Rajib i might be a stupid question, but i need to add also for portrait video so how can i do it. Is it works for only landscape. I tried it for portrait but not happening properly.
    – Gururaj
    Commented Dec 19, 2013 at 13:10
  • @Gururaj You should post the exact dimensions of the "portrait" video, the exact dimensions of the output ("frame") video. I'm not sure, but I think you can add it to your main question itself by editing.
    – Rajib
    Commented Dec 19, 2013 at 14:51
  • Rajib i have a portrait video of dimension 400*800 i want to add padding to make this as a square video. What command I should pass?. Please provide sample command for this particular dimension video.
    – Gururaj
    Commented Dec 20, 2013 at 6:55
  • @Gururaj only a guess but I think the vf parameter for you (assuming you want it horizontally centered with black padding on the sides) would be: -vf "pad=width=800:height=800:x=200:y=0:color=black" (y=200 because that's the extra 400 px padding / 2) Commented Aug 28, 2019 at 0:35
0

I had a hard time to crop and pad video and I had not find any suitable answer in my case that will explain this in full and simple words. Below is what I did. I had a video 1920(height)x1080(width). I wanted to crop above/below from height and keep the center -- from 1920 to become 1080. Then, to make width 1920 (from 1080) by creating padding that will put cropped video in the center. enter image description here

Full command:

ffmpeg -hwaccel vaapi -hwaccel_output_format yuv420p -vaapi_device /dev/dri/renderD128 -i myvid.mp4 -vf "crop=in_w:in_h-840, pad=1920:1080:ow/2:0:color=red, format=nv12, hwupload" -c:v hevc_vaapi -rc_mode CQP -global_quality 18 sample3sec_crop_with_REDpad_1920_1080.mp4

Explaining:

crop=in_w:in_h-840

  • To crop 840 pixels from height, if x, y not specified, ffmpeg "put" video in the center and crop 420 from above and below video. So a video with 1920 height will become 1920-840=1080 in height with cropping to happen above/below.

pad=1920:1080:ow/2:0

  • Then padding is created for video in order width to reach 1920 pixels (from 1080). Final video will be whatever dimensions you set in PAD: "1920:1080" = width x height.
  • then ow/2:0 says "put video in center of OUTPUT WIDTH (ow) (half distance) and then at "0" start point of height (place video at top - ceiling).

" -hwaccel vaapi -hwaccel_output_format yuv420p -vaapi_device /dev/dri/renderD128"

  • these options are for hardware acceleration, if GPU exists

pad=1920:1080:ow/2:0:color=red

  • make sure that PAD color is some vivid color, in order to check if result is ok.
  • Warning, check video players options for "fit video in screen".
  • ffplay was not at all accurate for me to show crop/pad results before encoding.

"-ss 0:00:00 -to 00:00:03"

  • Sample 3 seconds from your full lenght video, to see if the results is ok with you. Large videos may take even hours in old machines without fast modern cpu/gpu.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .