Skip to content

Instantly share code, notes, and snippets.

@MatteoGauthier
Last active February 29, 2024 10:45
Show Gist options
  • Save MatteoGauthier/d4e90bf53a61f383fd52408d9f0d9b12 to your computer and use it in GitHub Desktop.
Save MatteoGauthier/d4e90bf53a61f383fd52408d9f0d9b12 to your computer and use it in GitHub Desktop.
FFMPEG command snippets for video related processing

Get video framerates

Detailed video file information

ffprobe -loglevel 0 -print_format json -show_format -show_streams YOURFILE

List video files informations in the current directory

for file in *; do FPS=$(ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 "${file}"); FRAME_DURATION=$(echo "scale=10; 1 / ($FPS)" | bc); echo "$FPS $FRAME_DURATION $file"; done

Output :

# Frame rate | Duration of a frame | File name
120000/1001 .0083416666 C0999.MP4
120000/1001 .0083416666 C0999.MP4-noflicker.mp4
120000/1001 .0083416666 C1001.MP4
120000/1001 .0083416666 C1001.MP4-noflicker.mp4
120000/1001 .0083416666 C1008.MP4

Remove flickering from a video

With default x264 compression

ffmpeg -fflags +genpts -i YOUR_FILE -fflags +genpts -i YOUR_FILE -filter_complex "[0:v]setpts=PTS-STARTPTS[top]; [1:v]setpts=PTS-STARTPTS+.033/TB, format=yuva420p, colorchannelmixer=aa=0.5[bottom]; [top][bottom]overlay=shortest=1" -c:v libx264 -crf 26 -an NOFLICKER.mp4

Keep quality (lossless)

ffmpeg -fflags +genpts -i YOUR_FILE -fflags +genpts -i YOUR_FILE -filter_complex "[0:v]setpts=PTS-STARTPTS[top]; [1:v]setpts=PTS-STARTPTS+.033/TB, format=yuva420p, colorchannelmixer=aa=0.5[bottom]; [top][bottom]overlay=shortest=1" -c:v libx264 -crf 4 -qp 0 -an lossless.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment