I often need to perform some operations on videos or image sequences. Usually I use linux and `ffmpeg`, and sometimes I struggle to remember all the commands. Here is a collection of recipes that I usually use with a bit of explanations. Video conversions ========================== Cut a range of frames --------------------------- Cut a range of frames (100, 130) from a video and save it to mp4 with a good quality using x264 codec: ....
convert video to jpeg with good quality:
1 avconv -i input_video.mp4 -qmax 1 -qmin 1 images_%05d.jpg crop video:
1 avconv -i input.avi -vf crop=<width>:<height>:<x>:<y> output_%05d.png create gif using
http://gifmaker.me/
conversion with good jpeg quality:
1 avconv -i ./input.avi -q:v 1 output_frame_%05d.jpg
Using python and ffmpeg:
1 2 3 4 5 6 7 8 9 10 11 12 13 #!/usr/bin/python import glob import os t=glob.glob("*.avi" ) # search all AVI files for v in t: vv = os.path.splitext(v)[0]; os.makedirs( vv ) # make a directory for each input file pathDst = os.path.join( vv, "%05d.png" ) # deststination path os.system("ffmpeg -i {0} {1}".format( v, pathDst ) )
Trim 5 frames starting from 160-th frame and write to png sequence
ffmpeg -pix_fmt yuv420p -s 1920x1088 -r 1 -i input_video.yuv -r 1 -ss 160 -frames 5 output_sequence_%d.png size of input video is 1920x1088, format YUV420 progressive.
UPD: ffmpeg is renamed to avconv. Using it for trimming AVI video:
avconv -ss 00:58:00 -t 00:59:30 -i ./video.avi frame_%05d.png UPD2: it seems ffmpeg is back.