How to set default streams with ffmpeg
Asked Answered
N

2

5

I have some m4v files that I am wanting to add subtitles to with ffmpeg. I know I need to map the streams to get them into the output file but how do I ensure that this subtitle stream will be a default stream? The subtitles are .srt and people seem to be saying that they are not compatible with mp4 containers, what do I need to convert the subtitles to first?

Also, does it matter what order the various streams are in? Does the video stream always have to come first, followed by the audio, then the subtitles? Or can you mix them up however you want? Does it make any difference?

Lastly, what is the difference between a default stream and a forced stream?

Nine answered 23/7, 2013 at 14:13 Comment(0)
S
2

1. I have some m4v files that I am wanting to add subtitles to with ffmpeg.

m4v is the Apple knock off version of the non-platform specific MP4 standard. I don't know that much about this Apple format, but like most older container formats, I suspect it probably only supports audio/video or has poor or limited support for subtitles.

2. The subtitles are .srt and people seem to be saying that they are not compatible with mp4 containers, what do I need to convert the subtitles to first?

You can convert subtitles using a tool like AegisSub or Gaupol. However, my recommendation is to use MKVMerge tool that will produce an MKV file container, a container format that was designed to support a vast array of different streams, including subtitles (almost every type), fonts, and attachments. MKVmerge will also allow you to specify default streams.

3. Also, does it matter what order the various streams are in? Does the video stream always have to come first, followed by the audio, then the subtitles? Or can you mix them up however you want? Does it make any difference?

No. The type of each stream (video/audio/subtitle/other) is specified in the header. Players figure out which is which.

4. Lastly, what is the difference between a default stream and a forced stream?

Default stream is the one your player will default to if you haven't set your language preference code (ENG, JAP, SPA, ITA, etc.) in your player. Forced stream will force that stream regardless of the setting you specified in your player.

Slag answered 28/12, 2015 at 15:17 Comment(2)
ffmpeg can now also specify default streams. option -disposition:a:1 default will mark second audio as default, but don't forget to remove default tag from first track: e.g. -disposition:a:0 none or another type from the link. It will create a copy of the original file, so it's not instantaneous change, like when using mkvpropedit with --set flag-default option.Belita
m4v is mp4. exactly the same thing. Only difference is while using Quicktime won't play AC3 audio from mp4 file.Belita
P
1
  1. SRT file can be used as ffmpeg input to be remixed in a MP4 container. there is no compatibility problem.

    ffmpeg -i input.mp4 -i subtitles.srt -c:s mov_text -c:v copy -c:a copy output.mp4
    

    Here for mp4 you have to specify the subtitle codec mov_text.

  2. The order doesn't count, you can invert your input, you can invert audio/video and subtitle codec settings at the you will always have 3 track playing together.

    ffmpeg -i subtitles.srt -i input.mp4 -c:s mov_text -c:a copy -c:v copy output.mp4
    
  3. Not sure but here we explicitly set a codec for the subtitle it may be what you call "Forced". And it's a bit different of:

    ffmpeg -i input.mp4 output.mp4
    

    here ffmpeg will use its "default stream type" or codec to an MP4 output.

Perigon answered 23/7, 2013 at 22:46 Comment(5)
Sorry for the style, formatting answer from an iPhone is really hard!Perigon
They should give a badge for that.Siracusa
I had thought that the default/forced streams were to do with something during playback, thanks for the clarification. If I use the command you gave (ffmpeg -i input.mp4 -i subtitles.srt -c:s mov_text -c:v copy -c:a copy output.mp4) everything works well, however I initially had the output file as a .m4v file and it would give me a codec error straight away. I thought .mp4 and .m4v containers were the same so why would it give me an error with one but work with the other?Nine
3: a stream can have forced/default/<few more> tag. forced should play always, default by default. But it depend on the implementation of the mpeg decoder inside the device/program if the default tag is heeded, and if the order of streams is ignored. This applies to all steams: video/audio/subtitles. Also if subtitles inside mp4 are supported by the playing device. Some TVs will always play first stream by default. no matter the default tag.Belita
you have error while using m4v, because ffmpeg doesn't know what container to use. Container type is selected based on the extension of the output file. oufile.mp4 will use mp4 container. But using command -f you can specify the container type manually and use a non-standard output file extension. ffmpeg -i input.mp4 -i subtitles.srt -c:s mov_text -c:v copy -c:a copy -f mp4 output.m4vBelita

© 2022 - 2024 — McMap. All rights reserved.