This page is a collection of FFmpeg notes and snippets. It is a work in progress. If you have any questions or suggestions, please leave them in the comments. Last edited 1/22/2021.
Installing FFmpeg (YouTube videos)
Mac (without Macports)
macOS Catalina (without Macports)
Mac (with Macports)
Windows 10
Ubuntu 18.04 LTS
GoPro: convert images to timelapse video (files in multiple folders)
ffmpeg -framerate 30 -pattern_type glob -i "*/*.JPG" -vf crop="in_w:in_w*9/16,scale=1920:1080" -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
GoPro: convert images to timelapse video (files in single folder)
ffmpeg -framerate 30 -pattern_type glob -i "*.JPG" -vf "crop=in_w:in_w*9/16,scale=1920:1080" -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
Create Shortcut to Amcrest IP Camera
#!/bin/bash ffplay "rtsp://{username}:{password}@{ip_address}:554/cam/realmonitor?channel=1&subtype=0"; exit;
Streaming an IP Camera to a Web Browser
#!/bin/bash VIDSOURCE="rtsp://{username}:{password}@{ip_address}:554/cam/realmonitor?channel=1&subtype=0" AUDIO_OPTS="-c:a aac -b:a 160000 -ac 2" VIDEO_OPTS="-s 854x480 -c:v libx264 -b:v 800000" OUTPUT_HLS="-hls_time 10 -hls_list_size 10 -start_number 1" ffmpeg -i "$VIDSOURCE" -y $AUDIO_OPTS $VIDEO_OPTS $OUTPUT_HLS mystream.m3u8
Streaming Live TV from a HDHomerun to a Web Browser
#!/bin/bash VIDSOURCE="http://ip-address-of-hdhomerun:5004/auto/v11.1?transcode=internet240" AUDIO_OPTS="-c:a aac -b:a 160000 -ac 2" VIDEO_OPTS="-vcodec copy" OUTPUT_HLS="-hls_time 10 -hls_list_size 10 -start_number 1" ffmpeg -i "$VIDSOURCE" -y $AUDIO_OPTS $VIDEO_OPTS $OUTPUT_HLS mystream.m3u8
Stream a Mac Screen to a Raspberry Pi
#This lists audio/video sources on the Mac: ffmpeg -f avfoundation -list_devices true -i "" #Run this on the Mac: ffmpeg -f avfoundation -i "1" -vcodec h264_videotoolbox -realtime 1 -pix_fmt nv12 -b:v 5000k -f mpegts udp://ip_address_of_pi:1234 #Run this on the Raspberry Pi: omxplayer --timeout 60 ip_address_of_mac:1234
Make H.265 File Compatible with Quicktime
ffmpeg -i input.mp4 -codec copy -tag:v hvc1 output.mp4
Pipe ffmpeg to ffplay
ffmpeg -i -f h264 -vcodec libx264 pipe:1|ffplay -i pipe:0
Convert JPEG Image Sequence to MKV (with MJPEG encoding)
ffmpeg -framerate 30 -pattern_type glob -i 'timelapse/*.JPG' -codec copy out.mkv
Convert MKV (with MJPEG encoding) to JPEG Image Sequence
ffmpeg -i out.mkv -vcodec copy timelapse/pic%d.jpg
Extract Single JPEG Image from MKV (with MJPEG encoding)
ffmpeg -ss 00:00:00.03 -i out.mkv -vframes 1 -codec copy output.jpg
Creating an Elapsed Timer
ffmpeg -f lavfi -i color=c=black:s=240x96 -ss 00:00:00 -t 00:48:00 -vf "drawtext=fontfile=/System/Library/Fonts/Monaco.dfont:text='%{pts\:gmtime\:0\:%M\\\\\:%S}':fontcolor=white:fontsize=64:x=(w-tw)/2:y=(h-th)/2:box=1:boxcolor=green@0.5:boxborderw=10,format=yuv420p" timer.mp4
Create Timer with Transparent Background (Apple ProRes codec, prores_ks)
ffmpeg -f lavfi -i color=white@0.0:s=240x96,format=rgba -ss 00:00:00 -t 00:00:30 -vf "drawtext=fontfile=/System/Library/Fonts/Monaco.dfont:text='%{pts\:gmtime\:0\:%M\\\:%S}':fontcolor=white:fontsize=64:x=(w-tw)/2:y=(h-th)/2" -vcodec prores_ks timer_prores.mov
Create Scrolling Credits
ffplay -f lavfi -i color=green@0.0:s=1280x720:rate=60,format=rgba -ss 00:00:00 -t 00:01:30 -vf "drawtext=fontfile=/System/Library/Fonts/Supplemental/Impact.ttf:fontsize=60:fontcolor=green:x=(w-text_w)/2+20:y=h-40*t:line_spacing=80:textfile='names.txt'"
Note: On Window systems, access the fonts like this: “/Windows/Fonts/arial.ttf”. You can’t use the traditional “C:\Windows\Fonts\arial.ttf” because the colon is a reserved character in the FFmpeg syntax.
Add Background Image to an Audio File
ffmpeg -loop 1 -f image2 -i airplane.jpg -i train_whistle_audio.aac -vf crop=in_w:in_w*9/16,scale=1920:1080,fps=fps=30 -pix_fmt yuv420p -vcodec libx264 -shortest train_whistle_airplane.mp4
Add Solid Color Background to an Audio File
ffmpeg -i train_whistle_audio.m4a -f lavfi -i color=c=blue:s=640x480:r=15 -acodec copy -shortest train_whistle_blue_background.mp4
Extract Audio/Remove Video from a Video File
ffmpeg -i train_whistle.mp4 -vn -acodec copy train_whistle_audio.m4a
Extract Video/Remove Audio from a Video File
ffmpeg -i train_whistle.mp4 -vcodec copy -an train_whistle_no_audio.mp4
Add Silent Audio Track to a Video File
ffmpeg -i video_without_audio.mp4 -f lavfi -i anullsrc -vcodec copy -acodec aac -shortest video_with_silence.mp4
Speed Up Video 500x
ffmpeg -i sky.mp4 -vf "setpts=0.002*PTS,crop=in_w:in_w*9/16,scale=1920:1080" -vcodec libx264 -b:v 10000k -r 60 -pix_fmt yuv420p sky_speedier.mp4
Use every 500th Frame of Video
ffmpeg -i sky.mp4 -vf "select='not(mod(n,500))',setpts=N/FRAME_RATE/TB,crop=in_w:in_w*9/16,scale=1920:1080" -vcodec libx264 -b:v 10000k -r 60 -pix_fmt yuv420p sky_virtual_timelapse.mp4