Skip to content

Instantly share code, notes, and snippets.

@pinge
Last active July 18, 2023 18:51
Show Gist options
  • Save pinge/4d99435e342a8562a1a3d2960f2a6e7c to your computer and use it in GitHub Desktop.
Save pinge/4d99435e342a8562a1a3d2960f2a6e7c to your computer and use it in GitHub Desktop.
FFmpeg Cheatsheet

FFmpeg

remove audio from video file

ffmpeg -i example.mp4 -c copy -an example_no_audio.mp4

extract audio track from video file without re-encoding

ffmpeg -i input.mp4 -vn -acodec copy audio_track.aac

convert audio track to PCM 16 bit little endian

ffmpeg -i input.aac -acode pcm_s16le output.wav

resample audio track

ffmpeg -i input.wav -ar 16000 output.16khz.wav

downmix audio track stereo channels to mono

ffmpeg -i input.wav -ac 1 output.mono.wav

cut video based on seconds

ffmpeg -i input.mp4 -ss 00:00:00 -to 00:00:10 -c copy first_ten_seconds.mp4

crop a video

ffmpeg -i input.mp4 -filter:v "crop=width:height:x:y" -c:a copy crop.mp4

rotate a video with arbitrary angle

ffmpeg -i input.mp4 -vf "rotate=0.5*PI/180" -y rotate_half_degree_clockwise.mp4

extract first frame of a video

ffmpeg -i input.mp4 -vframes 1 -f image2 first_frame.png

extract a specific frame of a video

ffmpeg -i input.mp4 -vf "select=eq(n\,100)" -vframes 1 frame_100.png

slow down video by a factor

ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" 2x_slower.mp4

speed up video by a factor

ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" 2x_faster.mp4

smooth video with minterpolate filter

ffmpeg -i input.mp4 -filter:v "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120'" 120fps_smooth.mp4

blur video

ffmpeg -i input.mp4 -vf "boxblur=5:1" blurred.mp4

convert 59.9 fps video to 25 fps

ffmpeg -i input.mp4 -avoid_negative_ts 1 -vf fps=30000/1001 -r 25 output_25fps.mp4

strip metadata from video

ffmpeg -i input.mp4 -map_metadata -1 -c:v copy -c:a copy output_no_metadata.mp4

stabilize video

ffmpeg -i input.mp4 -vf vidstabdetect=stepsize=6:shakiness=8:accuracy=9:result=transform_vectors.trf -f null -

ffmpeg -i input.mp4 -vf vidstabtransform=input=transform_vectors.trf:zoom=1:smoothing=50,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -an output_stabilized.mp4

add 1:5 scaled watermark at the top-right corner of the video

ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=iw/5:h=ow/mdar[watermark][main];[main][watermark]overlay=x=main_w-overlay_w-(main_w*0.05):y=main_w*0.05;" -c:v libx264 -c:a copy output_with_watermark.mp4

create a 10s, 25fps video from a single sRGB PNG with the correct color profile

ffmpeg -i input.png -loop 1 -framerate 25 -t 10 -pix_fmt yuv420p -vf "colorspace=all=bt709:iprimaries=bt709:itrc=srgb:ispace=bt709" -color_range 1 -colorspace 1 -color_primaries 1 output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment