Skip to content

Instantly share code, notes, and snippets.

Embed
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

ref: http://superuser.com/questions/692990/use-ffmpeg-copy-codec-to-combine-ts-files-into-a-single-mp4

# 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

ref: https://ffmpeg.org/ffmpeg-bitstream-filters.html

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

Download Online AES-128 Encrypted HLS Video

ref: http://forum.videohelp.com/threads/343902-Looking-for-ts-to-mp4-conversion-tool

# 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

ref: http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality

# 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

ref: https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo

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

Fix Non-monotonous DTS in output

ref: https://forum.videohelp.com/threads/390057-FFMpeg-non-monotonous-DTS-in-output-stream-error#post2527823

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

1119035747 commented Jun 21, 2017

So difficulty

@GGACHA
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