Skip to content

Instantly share code, notes, and snippets.

@flymrc
Forked from cdeath/ffmpeg_mkv_ops.md
Created August 31, 2023 09:48
Show Gist options
  • Save flymrc/9632e1c17a9ec825e3ed6f6f2528f7c4 to your computer and use it in GitHub Desktop.
Save flymrc/9632e1c17a9ec825e3ed6f6f2528f7c4 to your computer and use it in GitHub Desktop.
extract stuff from .mkv with ffmpeg

Extract stuff from .mkv with ffmpeg

Full documentation: https://ffmpeg.org/ffmpeg.html

List all tracks

ffmpeg -i file.mkv

Types

v - video
a - audio
s - subtitles
t - attachments
d - data
m - metadata

Pick tracks

syntax

ffmpeg -i file.mkv -map 0:type -map 0:type -c copy newfile.mkv
ffmpeg -i file.mkv -map 0:type:index -map 0:type:index -c copy newfile.mkv

example

ffmpeg -i file.mkv -map 0:v -map 0:a:1 -map 0:s:1 -c copy newfile.mkv

Omit tracks (negative mapping)

syntax

ffmpeg -i file.mkv -map 0 -map -0:type:index -c newfile.mkv

example

ffmpeg -i file.mkv -map 0 -map -0:a:0 -map -0:s:0 -c newfile.mkv

Extract subtitle track

syntax

ffmpeg -i file.mkv -map 0:m:key:value -c:s copy|format file.srt

examples

ffmpeg -i file.mkv -map 0:m:language:eng -c:s copy file.srt
ffmpeg -i file.mkv -map 0:m:title:SDH -c:s copy file.srt
ffmpeg -i file.mkv -map 0:m:key:value -c:s srt file.srt

Batch operations

extract subtitles

for i in *.mkv; do ffmpeg -i "$i" -map 0:m:key:value -c:s copy "${i%.*}.srt"; done

pick tracks

for i in *.mkv; do ffmpeg -i "$i" -map 0:v -map 0:a:0 -map 0:s:0 -c copy "_${i}"; done

omit tracks

for i in *.mkv; do ffmpeg -i "$i" -map 0 -map -0:a:0 -c copy "_${i}"; done

Show only stats, warnings and errors

ffmpeg -v 24 -stats ...

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