Skip to content

Instantly share code, notes, and snippets.

@stephenscaff
Last active October 24, 2022 23:19
Show Gist options
  • Save stephenscaff/bd3bc3152e5079e54dd78c1ef59f7348 to your computer and use it in GitHub Desktop.
Save stephenscaff/bd3bc3152e5079e54dd78c1ef59f7348 to your computer and use it in GitHub Desktop.
Useful ffmpeg commands
# FFMPEG Cmds
# https://ffmpeg.org/ffmpeg-all.html#Video-Options
# -i input file
# Basic convert mov to mp4
ffmpeg -i input.mov output.mp4
# Simple Compress ( amount by -b 2500k)
# -b: bitrate
# -an: disables audio
ffmpeg -i input.mp4 -b 2500k -an output.min.mp4
# High-quality Encoding
# crf (Constant Rate Factor) param controls output quality.
# The lower crf, the higher the quality (range: 0-51). The default value is 23
# -c[:stream_specifier] codec (input/output,per-stream)
# -codec[:stream_specifier] codec (input/output,per-stream)
# eg: -c:v libx264: encodes all video streams with libx264
# Encode and Legit Compress (compression amount by -crf 30)
ffmpeg -i input.mp4 -c:v libx264 -crf 30 output.mp4
# Create a cut at start / end, compress
ffmpeg -i input.mp4 -ss 00:02 -to 00:10 -c:v libx264 -crf 30 output.mp4
# Increase Playback speed, using setpts filters
# Increase speed by x 10
ffmpeg -i input.mp4 -filter:v "setpts=PTS/10" output.mp4
# Cropping
# Crop filter has 4 params w, h, x and y
# ie: crop=100:100:0:0 means "crop the 100 x 100 pixels from top right corner"
ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4
# Reverse a vid
ffmpeg -i input.mp4 -vf reverse output_reversed.mp4
# Forward & Reverse - Create a vid that contacts the vid in reverse (no audio)
ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" output.mp4
# Forward & Reverse - with filter (has audio)
ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][0:a][r] [0:a]concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4
# Speed up vid
ffmpeg -i input.mp4 -r 16 -filter:v "setpts=0.35*PTS" output.faster.min.mp4
# Concat multi vids
# 1 - Create Txt file with vids (in vids directory)
echo file file1.mp4 > list.txt
echo file file2.mp4 >> list.txt
# 2 - Concatenate Files
ffmpeg -f concat -i list.txt -c copy output.mp4
# Triming
# -i: Input file
# -ss: start time, e.g. 00:01:23.000 or 83secs (If this is placed before the input file it seeks to this position in the input file. If it's after the input it will split from that exact position.)
# -t: duraction of clip
# -to: end time
# -c: copies without re-encoding
# -avoid_negative_ts make_zero: Sets the first timestamp as 0
# The times are passed in parsed eg 00:00:10.456
# The output file is the last part of the command
# ex: ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
ffmpeg -i input.mp4 -ss 0:00:00 -to 0:00:06.5 output.mp4
# Trim With Re-encoding
# leave out -c (copy) param to automatically re-encode output
# eg: ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4
# Take Screen Grab of Frame
ffmpeg -ss 00:00:01 -i input.mp4 -frames:v 1 -q:v 2 output.jpg
# Extract Frames
# To extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:
ffmpeg -i input.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 output.png
# To extract one frame per second only:
ffmpeg -i in.mp4 -fps=1 -vsync 0 output.png
# Create a video slideshow from images
# -r: marks the image framerate (inverse time of each image);
# -vf: fps=25 marks the true framerate of the output.
ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
# EQ Filters
# Adjust Brightness
ffmpeg -i gateway.min.mp4 -vf eq=brightness=0.06 -c:a copy gateway.b2.min.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment