Stripping an Audio Track out of a Video File Using ffmpeg
I received a video that has multiple audio streams, subtitles, and one video stream. The client wanted only the video and english subtitles:
Using ffprobe to look at the file:
$ ffprobe test.mkv
(removed some build info that is printed out)
Input #0, matroska,webm, from 'test.mkv':
Metadata:
title : Il test
creation_time : 2023-08-22T20:25:22.000000Z
Duration: 00:35:04.86, start: 0.000000, bitrate: 6783 kb/s
Stream #0:0: Video: h264 (High), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
BPS : 6268605
DURATION : 00:35:04.853000000
NUMBER_OF_FRAMES: 50466
NUMBER_OF_BYTES : 1649311676
Stream #0:1(ita): Audio: eac3, 48000 Hz, 6 channels, fltp (default)
Metadata:
BPS : 256000
DURATION : 00:35:04.864000000
NUMBER_OF_FRAMES: 65777
NUMBER_OF_BYTES : 67355648
Stream #0:2(eng): Audio: eac3, 48000 Hz, 6 channels, fltp
Metadata:
BPS : 256000
DURATION : 00:35:04.832000000
NUMBER_OF_FRAMES: 65776
NUMBER_OF_BYTES : 67354624
Stream #0:3(ita): Subtitle: subrip (default) (forced)
Metadata:
BPS : 7
DURATION : 00:29:21.593000000
NUMBER_OF_FRAMES: 38
NUMBER_OF_BYTES : 1603
Stream #0:4(ita): Subtitle: subrip
Metadata:
BPS : 81
DURATION : 00:34:50.755000000
NUMBER_OF_FRAMES: 595
NUMBER_OF_BYTES : 21319
_STATISTICS_WRITING_APP: mkvmerge v77.0 ('Elemental') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2023-08-22 20:25:22
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:5(eng): Subtitle: subrip
Metadata:
BPS : 99
DURATION : 00:34:59.849000000
NUMBER_OF_FRAMES: 787
NUMBER_OF_BYTES : 26236
_STATISTICS_WRITING_APP: mkvmerge v77.0 ('Elemental') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2023-08-22 20:25:22
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:6(eng): Subtitle: subrip
Metadata:
title : SDH
BPS : 109
DURATION : 00:34:59.849000000
NUMBER_OF_FRAMES: 882
NUMBER_OF_BYTES : 28799
_STATISTICS_WRITING_APP: mkvmerge v77.0 ('Elemental') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2023-08-22 20:25:22
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
It has these streams:
Stream #0:0: Video: h264 (High) ...
Stream #0:1(ita): Audio: eac3, ...
Stream #0:2(eng): Audio: eac3, ...
Stream #0:3(ita): Subtitle
Stream #0:4(ita): Subtitle
Stream #0:5(eng): Subtitle
Stream #0:6(eng): Subtitle
To extract only the video and english audio and subtitles, run this command:
$ ffmpeg -i input.mkv -map 0:v:0 -map 0:s:2 -map 0:s:3 -map 0:a:1 -c copy test.mkv
Details of the command options:
-i input.mkv : Input file
-map 0:v:0 : Grab the first video stream
-map 0:s:2 : Grab the second subtitle stream (it was English)
-map 0:s:3 : Grab the third subtitle stream (it was English-SDH)
-map 0:a:1 : Grab the second audo stream (the english one)
-c copy : copy the streams, don't reencode.
test.mkv : Output file