I want to convert several video files (captured from television) to another format, but I want to remove some specific streams. For example, this is one of my input files:
$ ffprobe -hide_banner -i 'Easy Rider.ts' 2>&1|grep Stream
Stream #0:0[0x4f6]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:1[0x4fc]: Unknown: none ([12][0][0][0] / 0x000C)
Stream #0:2[0x13f7]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
Stream #0:3[0x13f8](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:4[0x13f9](fra): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:5[0x13fa](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
Stream #0:6[0x13fb](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
Stream #0:7[0x13fc](mul): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:8[0x13fd](mis): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s (visual impaired) (descriptions)
Stream #0:9[0x13fe](fra): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:10[0x13ff](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
From this file, I want to keep
- Stream #2 (h264 video)
- Stream #3 (mp2 audio in german)
- Stream #10 (dvb_subtitle in german)
In other words, I want to exclude from conversion
- all streams of unknown type
- all audio streams other than german
- all streams for visual impaired or hearing impaired
- all dvb_teletext streams
Of cause, I can do some awk
scripting to construct a command like
$ ffmpeg -hide_banner -ignore_unknown -i 'Easy Rider.ts' -map 0:2 -map 0:3 -map 0:10 -vcodec copy -acodec copy -scodec copy xx.ts
But I am searching for a solution using ffmpeg
's mapping facilities.
I already found Mapping streams by language in FFmpeg, which led me to
$ ffmpeg -hide_banner -ignore_unknown -i 'Easy Rider.ts' -map 0:v -map 0:m:language:deu -vcodec copy -acodec copy -scodec copy xx.ts
This command creates a file, which still has subtitles for hearing impaired and the dvb_teletext in it
$ ffprobe -hide_banner -i xx.ts 2>&1|grep Stream
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
Stream #0:1[0x101](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:2[0x102](deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006), 492x250
Stream #0:3[0x103](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
Stream #0:4[0x104](deu): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Up to now, I did not find a way to exclude those streams from the output. Any idea?