85.6 Video Image Crop

20210502 This section deals with cropping the video image over the extent of the video. If you are wanting to extract time extents of the video (i.e., trim or cut the video) see Section 85.13.

Using ffmpeg we can remove, for example, the right most 230 pixel wide margin of a video with the following command.

\$ ffmpeg -i input.mp4 -vf "crop=iw-230:ih:0:0" cropped.mp4

The input video is identified using -i. Video filtering is introduced with -vf as a shorthand for -filter:v. A filtergraph is provided as the argument to the video filtering. The final parameter names to output video file.

A crop filter is utilised through the filtergraph. The filter’s first parameter is the width of the output video. Here, iw refers to the original input video’s width from which we subtract the amount that we wish to crop. The second parameter is the height of the output video which using ih as the input video height retains the original height. The next two parameters are the x (horizontal) and y (vertical) positions of the input video that will become the left and top edge of the output video. Thus 0:0 indicates no cropping on the left or the top.

The filtergraph crop=iw-230:ih:0:0 will crop 230 pixels from the right edge of the video, for every frame.

Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.