18 May, 2009

FFmpeg Ninja Moves - part 4

Continuing on our FFMpeg trek, this post will focus on manipulating frame sizes; specifically, cropping, resizing and padding.

Selectively cropping out a portion of each frame in the video allows you to focus on particular regions. The input video has 720x480 dimensions, suppose you were only interested in the inner 360x240 frame contents. You can crop the video frames by specifying the left, right, top and bottom crop bands (specified in pixels). As an example, the following command crops the innter 360x240 frame contents.

$ ffmpeg -i /tmp/video.avi -croptop 120 -cropbottom 120 -cropleft 180 -cropright 180 /var/tmp/video.avi

If instead of cropping the image you wish to resize it, you can specify a desired frame size WxH. For example, if you wish the output video file dimensions to consist of 360x240 you can specify the -s size specifier as follows:

$ ffmpeg -i /tmp/video.avi -s 360x240 /var/tmp/video.avi

Unlike cropping, all frame contents are retained but the lesser dimensions gives the effect of dropping every other pixel contents.

If you require expanding the video dimensions you can pad the left, right, top and bottom to attain the desired frame dimensions. To convert the 720x480 video dimensions to 800x600 you can specify

ffmpeg -i /tmp/video.avi -padtop 40 -padbottom 40 -padleft 60 -padright 60 -padcolor FFFFFF /var/tmp/video.avi

I specified a white pad color to allow you to see the pad effects. A keen reader will notice that in order to preserve the aspect ratio the output video is actually 840 x 560.

No comments: