FFMPEG Cropping and Re-sizing (order matters)

471

I discovered something whilst trying to crop and re-size a video with FFMPEG: the order of switches actually matters! I couldn’t find any mention of this in the documentation, and nowhere could I find an explanation of why my video was being cropped after it was resized. The video I was re-encoding had some fuzziness at the top, and an ugly black border down the right-hand side. I wanted to remove these, but have a fixed output size.

Here’s an example. Our input file, input.avi is a 640×480 video.

We run the following 2 commands:

ffmpeg -i input.avi -s qvga -croptop 8 -cropright 22 output1.avi
ffmpeg -i input.avi -croptop 8 -cropright 22 -s qvga output2.avi

Notice that in the first case, we’ve set the size first (qvga means 320×240).

In the second case we set the cropping first.

Now let’s look at the output with: file *.avi.

input.avi: RIFF (little-endian) data, AVI, 640 x 480, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 44100 Hz)
output1.avi: RIFF (little-endian) data, AVI, 298 x 232, 25.00 fps, video: FFMpeg MPEG-4, audio: MPEG-1 Layer 1 or 2 (stereo, 44100 Hz)
output2.avi: RIFF (little-endian) data, AVI, 320 x 240, 25.00 fps, video: FFMpeg MPEG-4, audio: MPEG-1 Layer 1 or 2 (stereo, 44100 Hz)

As you can see, the first output file has its dimensions cropped after resizing. The second one before, and its the second one I wanted, cropping the video first, then resizing it.

I have never encountered a command-line app where the order of the switches actually mattered, until now. I don’t know how many other ffmpeg switches this also applies to, but I thought I’d share it as I personally couldn’t find anything about it elsewhere.

Hope this is helpful!

Thom