Skip to content

Example: video cropping

suntong edited this page Nov 5, 2018 · 5 revisions

Extract image frames

First, use the fastest way to extract frame images using ffmpeg, one frame per minute for 10 frames:

$ time for i in {0..9} ; do ffmpeg -ss `echo $i*60.0 | bc` -i input.webm -frames:v 1 period_down_$i.jpg ; done
real	0m0.637s
user	0m0.616s
sys	0m0.106s

Measures

Measure the picture size and determine the cropping:

$ identify period_down_1.jpg
period_down_1.jpg JPEG 492x360 492x360+0+0 8-bit sRGB 25.7KB 0.000u 0:00.000

display period_down_1.jpg

Decide to crop 45 pixels from the top, and 45 from the bottom.

Cropping

To crop 45 pixels from the top, and 45 from the bottom, and from a particular point, say 00:01:00 in the video for a specific duration(40 seconds), use the combination of '-ss' and '-t' with the cropping:

 ffmpeg -i input.webm -ss 00:01:00 -t 40 -filter:v "crop=in_w:in_h-90" -c:a copy out.webm
  • The filter will automatically center the crop if x and y are omitted such as in this example.

  • Try out the out.webm, if all is well, then start the real cropping without the limited duration.

    date; nice ffcvt -nc -debug 1 -d . -w $FFCVT_DST -p -- -filter:v "crop=in_w:in_h-90"; date