FFmpeg Notes

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 2/24/2020.

Installing FFmpeg (YouTube videos)

Mac (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_w9/16,scale=1920:1080 -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
Create Shortcut to Amcrest IP Camera
ffplay "rtsp://{username}:{password}@{ip_address}:554/cam/realmonitor?channel=1&subtype=0";
Streaming an IP Camera to a Web Browser
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
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.

Leave a comment

Your email address will not be published. Required fields are marked *