brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -map 0 keeps every track, where the default keeps only one of each

Ffmpeg
~/tips/tip-ffmpeg-map-0-all-streams

ffmpeg -i film.mkv -map 0 -c copy film-copy.mkv

Makes ffmpeg copy all audio and subtitle tracks instead of picking one per type.

This one surprises a lot of people. Convert a film with three audio tracks and two subtitle tracks, and the output has one of each, or no subtitles at all.

Without -map, ffmpeg picks streams by itself: the best video stream, the best audio stream and one subtitle stream, if the output format can hold it. Everything else is dropped without a warning. Adding -map 0 says “take every stream from the first input”:

ffmpeg -i film.mkv -map 0 -c copy film-copy.mkv

With a file that has one video and two audio streams, the plain command writes two streams and the one with -map 0 writes all three.

You can also be selective. -map 0:v -map 0:a keeps all video and audio but no subtitles, and -map 0 -map -0:s:1 keeps everything except the second subtitle track. The minus in front removes a stream again.

The caveat comes with the container. MKV takes nearly anything, but MP4 can’t store most subtitle formats or attachments like fonts. With -map 0 into an MP4 you may get an error about a stream the muxer doesn’t support. Then I’d either drop those streams with a negative map or stay with MKV.

Further reading: ffmpeg documentation, FFmpeg wiki: Map

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link