ffmpeg Cheat Sheet

Table of Contents

Converting To TS Files

H264 -> TS

ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts

Concatenating H264 Files

Look here:

First convert the H264 files to TS files using the command above. Then concatenate them like this:

ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4

Cutting Clips

This is stolen from here:

First, if you're working with an H264 file you should converti it into a TS file. Then you can do this:

"The following would clip the first 30 seconds, and then clip everything that is 10 seconds after that:"

ffmpeg -i input.ts -ss 00:00:30.0 -c copy -t 00:00:10.0 output.ts

Encoding Examples

Youtube

Naturally, this assumes that you're working with a TS file.

ffmpeg -i <input file> -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart <output_name>.mp4

Recording Screencasts

Please note the screen size and change it based on your monitor. This value below works well with my laptop's built-in screen:

ffmpeg -video_size 1366x768 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -i pulse output.mkv

Also please note that I'm running Debian Linux. This command is slightly different based on your OS, Linux distribution or season.

Flipping Videos 180 Degrees

I'm having a lot of problems doing this in ffmpeg, so I punt to Handbrake instead:

Stripping The Audio Portion From An MP4

First, see what format the audio track uses:

ffmpeg -i input.mp4 2>&1 | grep Stream

If the audio file use the AAC format then strip it out like so:

ffmpeg -i input.mp4 -vn -acodec copy output.aac

Converting AAC Files To MP3

ffmpeg -i ./input.aac -c:a libmp3lame -ac 2 -q:a 2 output.mp3

Last Updated .