Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

ffmpeg Cheatsheet

  • Join TS Files
  • Convert TS to MP4
  • Download Online AES-128 Encrypted HLS video
  • Convert Video to GIF
  • Extract Audio and Convert it to MP3
  • Burn Subtitles into Video

Join TS Files


# create ts filelist as following format:
file '<filepath>'
# or use following command to generate:
(for %i in (*.ts) do @echo file '%i') > ts.lst

# concat the ts files by ffmpeg
ffmpeg -f concat -i ts.lst -c copy all.ts

Convert TS to MP4


ffmpeg -i <source.ts> -c copy -bsf:a aac_adtstoasc <target.mp4>

Download Online AES-128 Encrypted HLS Video


# step 1: download m3u8 and key file
# step 2: modify key file path in m3u8 file
# step 3: download m3u8
ffmpeg [-protocol_whitelist "file,http,https,tcp,tls"] -i <source.m3u8> -c copy <target.ts>

Or just use:

ffmpeg -allowed_extensions ALL -protocol_whitelist "file,http,tcp,https,tls,crypto,httpproxy" -i <source.m3u8> -c copy <target.ts>

Convert Video to GIF


# extract frames from video
mkdir frames
ffmpeg -i <input.mp4> -vf scale=320:-1 -r 10 frames/ffout%03d.png

# merge frames to gif
convert -delay 5 -loop 0 [-crop '100%x56%'] frames/ffout*.png <output.gif

Extract Audio and Convert it to MP3

ffmpeg -i <input.mp4> <out.mp3>

Burn Subtitles into Video


ffmpeg -i video.avi -vf "yadif, ass=subtitle.ass" out.avi

Fix Non-monotonous DTS in output


ffmpeg -fflags +igndts -i MOVIE.ts -map 0:0 -map 0:2 -c:v copy -c:a copy OUTPUT.mp4
Copy link

1119035747 commented Jun 21, 2017

So difficulty

Copy link

GGACHA commented Dec 25, 2021

hello sir, if ffmpeg can only add key and all .ts files to decrypt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment