Skip to content

Instantly share code, notes, and snippets.

@rch850
Last active February 13, 2024 09:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rch850/80470821cb91b2b0210100e5e27cdbb8 to your computer and use it in GitHub Desktop.
Save rch850/80470821cb91b2b0210100e5e27cdbb8 to your computer and use it in GitHub Desktop.
ffmpeg command history

Degrade HD movie

$ ffmpeg -i source.mp4 -vf fps=fps=15,scale=480:-1 -b:v 450k -b:a 50k out.mp4

Convert mp4 into gif and scale it with maintaining aspect ratio.

$ ffmpeg -i in.mp4 -vf scale=1024:-1 out.gif

Convert mp4 into gif, set fps, and scale it to half size with maintaining aspect ratio.

$ ffmpeg -i in.mp4 -vf fps=fps=30,scale=w=iw/2:-1 out.gif

Convert mp4 into fMP4 hls.

ffmpeg -i ~/20200526_200518.mp4 -f hls -hls_segment_type fmp4 -hls_playlist_type vod -c:v copy stream.m3u8

Crop a video temporally and spatially (width=1300, height=1200, x=1700, y=3000, from 00:10 to 00:22).

$ ffmpeg -i in.mp4 -vf "crop=1300:1200:1700:300" -ss 00:10 -t 00:12 out.mp4

Create LGTM gif

$ ffmpeg -i input.mp4 -filter_complex drawtext="fontfile=/System/Library/Fonts/Helvetica.ttc:fontsize=160:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:text='LGTM'" -t 00:00:03 output.gif

Make video 2x speed.

$ ffmpeg -i in.mp4 -vf setpts=PTS/2.0 -af atempo=2.0 out.mp4

Extract .wav file from .mp4 in 44.1kHz stereo.

$ ffmpeg -i in.mp4 -t 00:10:00 -ac 2 -ar 44100 out.wav

mp4 to ts

  • from 00:01:00, duration 10s
  • length of ts file is 0.666s
ffmpeg -i in.mp4 -g 10 -hls_time 0.666 -ss 00:01:00 -t 00:00:10 out.m3u8

Generate video from png

$ ffmpeg -framerate 5 -i 'one-image.png' -pix_fmt yuv420p movie.mp4

$ ffmpeg -framerate 5 -pattern_type glob -i 'image*.png' -pix_fmt yuv420p movie.mp4

Mute video

$ ffmpeg -i in.mp4 -an out.mp4

Audio

Merge 2 audio files

ffmpeg -i recorded.wav -i bgm.mp3 -filter_complex amerge -ac 2 -c:a libmp3lame -q:a 4 output.mp3

Streaming

Publish rtmp stream from mp4 file

ffmpeg -y -stream_loop -1 -re -i ~/20200526_200518.mp4 -f flv rtmp://192.168.11.7:1935/app/stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment