Skip to content

Instantly share code, notes, and snippets.

@dudewheresmycode
Created August 18, 2022 20:42
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 dudewheresmycode/bbc26e4a0a7211237e4bb02307a910ef to your computer and use it in GitHub Desktop.
Save dudewheresmycode/bbc26e4a0a7211237e4bb02307a910ef to your computer and use it in GitHub Desktop.

Generate 2min of colorbars and audio

ffmpeg \
-f lavfi -i "sine=frequency=1000:duration=120" \
-f lavfi \
-i testsrc=duration=5:size=1280x720:rate=24 \
-t 120 \
-map 0:0 \
-map 1:0 \
-c:v libx264 -crf 17 -maxrate 2M -bufsize 4M \
-c:a aac -ac 2 -b:a 192k \
OUTPUT_FILE.mp4

Capture Desktop + Audio Linux

ffmpeg -f pulse -i alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1.monitor -ac 2 \
-video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 \
-c:v libx264rgb -crf 0 -preset ultrafast -color_range 2 \
-y captured.mkv

Add text to video

ffmpeg -i INPUT_VIDEO.MOV \
-vf "scale=1280:-2,drawtext=fontfile=/PATH/TO/FONT.TTF:text='Hello World':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=20:y=20" \
-c:v libx264 -crf 20 -maxrate 2M -codec:a aac -ac 2 -b:a 128k \
OUTPUT_VIDEO.mp4

Extract EIA-608 captions from H.264

ffmpeg \
-f lavfi -i "movie=/PATH/TO/INPUT.ts[out+subcc]" \
-map v -c libx264 -maxrate 15M -crf 10 -c:a aac -b:a 320k \
-bsf:v "filter_units=remove_types=6" \
STRIPPED.mp4 \
-map s -c:s srt \
SUBTITLE.srt

Tip: To strip the EIA-608 from the video add the line -bsf:v "filter_units=remove_types=6"

Convert mono tracks to one stereo audio file (256K MP3)

ffmpeg -i left.wav -i right.wav \
-filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" \
-map "[a]" -b:a 256k \
output.mp3

Combine 2 mono streams into one stereo audio file (192K MP3)

ffmpeg -i INPUT.MOV \
-filter_complex '[0:0][0:1]amerge=inputs=2[a]' \
-map '[a]' -vn -ac 2 -b:a 192k \
OUTPUT.mp3

Combine 8 mono streams into one stereo audio file (192K MP3)

ffmpeg -i INPUT.MOV \
-filter_complex '[0:0][0:1][0:2][0:3][0:4][0:5][0:6][0:7]amerge=inputs=8[a]' \
-map '[a]' -vn \
-ac 2 -b:a 192k \
OUTPUT.mp3

Downmix Video 5.1 and output H.264 Video + stereo AAC audio

ffmpeg -i INPUT.MOV \
-filter_complex '[0:1][0:2][0:3][0:4][0:5][0:6][0:7]amerge=inputs=7[a]' \
-map 0:v:0 -map '[a]' \
-c:v libx264 -preset veryfast -crf 22 \
-c:a aac -ac 2 -b:a 192k \
OUTPUT.mkv

Generate H.264 video + silent stereo audio from an image

ffmpeg -f lavfi \
-i anullsrc=channel_layout=stereo:sample_rate=44100 \
-loop 1 -i image.jpg \
-c:v libx264 -t 3600 -pix_fmt yuv420p \
-c:a aac -ac 2 -b:a 128k -r 24 \
OUTPUT.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment