How to set default streams with ffmpeg

13,211

Solution 1

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.

Solution 2

  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.

Share:
13,211
Sam
Author by

Sam

Updated on June 22, 2022

Comments

  • Sam
    Sam about 2 years

    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?