I am looking to take a video and compress it in a way that is similar to the compression that Instagram uses. What ffmpeg command can do this?
Instagram currently uses x264 to encode video, and the single video I looked at was cropped to 640x640 and had no audio.
The encoding information was not removed from the sample so you can probe it to infer what encoding options were used.
$ strings input.mp4 | grep x264
x264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=8 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=1638 vbv_bufsize=3276 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=2:1.00
Alternatively you can use mediainfo
to get this info.
Basically the default settings (-crf 23
-preset medium
) are being used in my sample with a few additional options:
ffmpeg -i input -maxrate 1638k -bufsize 3276k -psy 0 -aq-mode 2 -movflags +faststart output.mp4
I would not bother with copying these settings verbatim (especially -psy 0
), and would experiment with a simpler command to see what works best for your needs. See FFmpeg Wiki: H.264.
This example doesn't perform the cropping. See the crop and/or scale filters to do that.