ffmpeg

<< Back to wiki homepage

Table of contents:

Slowing down / speeding up a video

Increase PTS value for slowing down even more. Decrease below 1.0 to speed up:

ffmpeg -i input_video_or.gif -filter:v "setpts=1.5*PTS,minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120'" output.mp4

You can remove minterpolate section on speedups.

Cutting a part of a video

-ss gives "start time" and -t gives "duration":

ffmpeg -ss 00:57:42.0 -i input.mp4 -c copy -t 00:00:08.0 output.mp4

If there are some sync issues (e.g. black screen, late sound etc.) that means you need to re-encode, use something like: -c:v libx264 -crf 18 -c:a copy instead of -c copy

Adding meme-like captions to a video

You might want to adjust y= value depending on video size:

ffmpeg -i $inputfile -filter_complex \
"[0:v]pad=iw:ih+100:0:(oh-ih)/2:color=white, \
 drawtext=text='USE FFMPEG THEY SAID':fontfile=/path/to/impact_font.ttf:fontsize=24:x=(w-tw)/2:y=(50-th)/2, \
 drawtext=text='IT WILL BE OK THEY SAID':fontfile=/path/to/impact_font.ttf:fontsize=24:x=(w-tw)/2:y=h-25-(th/2)" \
output

Convert video to gif

Includes scaling, adjust as you like. Also uses imagemagick's convert:

ffmpeg -i $input_video -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - | convert -delay 10 - -loop 0 -layers optimize output.gif