Skip to content

Instantly share code, notes, and snippets.

@yunntan
Last active October 23, 2020 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunntan/9cb856b2d1548e519ac24c68c9f7bf97 to your computer and use it in GitHub Desktop.
Save yunntan/9cb856b2d1548e519ac24c68c9f7bf97 to your computer and use it in GitHub Desktop.

Extract frames as JPGs:

ffmpeg -i video.mp4 -r 24 -f image2 img/img_%5d.jpg

-r: frame rate

Extract frame at specific time:

ffmpeg -i video.mp4 -ss 00:00:01.000 -f image2 -vframes 1 myImage.jpg

Extract audio:

ffmpeg -i video.mp4 -vn -ar 22050 -ac 2 -ab 128k -f mp3 audio.mp3

Convert to H.264 AAC:

ffmpeg -i video.mov -c:v libx264 -acodec aac -strict -2 output.mp4

Web Optimized:

-movflags +faststart -profile:v baseline -level 4.0

Scale quality:

-qscale x

( 0 <= x >= 10 )

Scale based on input size :

-vf scale="iw/1:ih/2"

Truncate video:

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

Padding Sample:

ffmpeg -i video.mp4 -vf "scale=320:160,pad=363:200:0:20" out.mp4

Crop video:

-filter:v "crop=width:height:x:y"

Merge multiple videos together

ls Movie_Part_1.mp4 Movie_Part_2.mp4 | perl -ne 'print "file $_"' | ffmpeg -f concat -i - -c copy Movie_Joined.mp4

Convert to mp3 SAFE + web compatible

ffmpeg -i audio.wav -vn -sn -c:a mp3 -ab 192k audio.mp3

Low weight Stereo mp3

ffmpeg -i audio.mp3 -vn -ar 44100 -ac 2 -ab 96k -f mp3 output.mp3

Audio fade out

ffmpeg -i input.mp3 -af 'afade=t=out:st=27:d=4' -vn -sn -c:a mp3 -ab 192k fadeout.mp3

Audio truncate (time in seccond)

ffmpeg -i input.mp3 -ss 59 -t 31 cut.mp3

Count frames in a video

ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 movie.mp4

Video fade in/out

-vf "fade=out:400:50" (fade out from frame 400 - lasting for 50 frames)

Remove audio from video

-an

Scale h.264 quality

-crf {x} ( 0 <= x >= 51 ) (0 = no compression)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment