Scaling and cropping

With mencoder use the -vf (video filter) option to enable one or more of the following filters:

  • scale=w:h:i for scaling
  • crop=w:h:x:y for cropping
  • expand=w:h:x:y for expanding (adding borders)

The x and y specify the coordinates of the cropped (when cropping) or the original (when expanding) picture. When these arguments are left out, Mencoder will center. The i is either 1 (interlaced) or 0 (not interlaced) and will default to 0. The w and h denote the width and height of the result. When expanding, negative numbers are treated as offsets to the original video, so applying -50:-25 to a 800x600 movie, will result in picture size 850x625.

Say we wanted an Ogg Theora video of 1280x1024 scaled down to 800x600 without stretching, and saved as an MJPEG. In this example we first scale down to 750x600. Then we will expand to 800x600 and convert the result to an MJPEG video. The scaling and expanding combo will make sure the video is not stretched in any way.

mencoder -idx infile.ogv -vf scale=750:600,expand=-50:0 -ovc lavc -oac pcm -lavcopts vcodec=mjpeg -o outfile.avi

Another example. Input is a 1920x1080 MP4 from a full HD camera, and output is a 960x540 MJPEG, suitable for editing:

mencoder -idx input.mp4 -vf scale=960:540 -ovc lavc -oac pcm -lavcopts vcodec=mjpeg -o output.avi