Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#9105 closed defect (fixed)

Cannot set dispositions for subtitle streams inside MKV other than Default and Forced

Reported by: droid-xx Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: disposition mkv
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


I'm not sure whether this is a bug or a feature but I'm filing this since the documentation on disposition types is lacking details.

If this is a feature, then there's probably some internal checking by ffmpeg to determine whether the disposition type given by the user can be applied to the selected stream. So obviously if you pass a disposition type of "attached_pic" to a subtitle it won't make any sense, hence nothing will change in the output disposition-wise (although there's no error or warning displayed to inform the user about this, and the documentation doesn't state which dispositions apply to which types of streams).

However there are at least 2 more dispositions that can be set for subtitle streams: "karaoke" (for ass/ssa which are designed as karaoke subtitles) and "hearing_impaired" (for SDH subtitles).

This works for the third subtitle track inside an .mkv with a total of 3 subtitle streams:

ffmpeg -i input.mkv -map 0 -c copy -disposition:s:2 forced output.mkv

This won't work (disposition is ignored with no errors/warnings):

ffmpeg -i input.mkv -map 0 -c copy -disposition:s:2 hearing_impaired output.mkv
ffmpeg -i input.mkv -map 0 -c copy -disposition:s:2 karaoke output.mkv

Change History (8)

comment:1 by droid-xx, 15 months ago

I forgot to mention the "lyrics" disposition which should also be configurable for a subtitle stream.

comment:2 by mkver, 15 months ago

There are no internal checks whether a disposition can be applied at all; instead most muxers just don't check the disposition at all, because the format either does have anything that one can map these dispositions to or because doing so is just unimplemented. And if a muxer supports a specific disposition flag, it only checks for whether this flag is set or not and ignores all the others.

The Matroska muxer is one of the few muxers that preserve some dispositions. But it can only preserve those dispositions for which there is a matching Matroska element. This is not so for karaoke and up until very recently it was also not true for hearing_impaired. I have just sent a patchset that implements support for hearing_impaired and a few other dispositions that Matroska now supports.

Matroska always allowed to preserve the attached_pic disposition (for video streams only); it is just unimplemented. I need to finally finish this.

comment:3 by droid-xx, 15 months ago

Initially when I created this ticket I thought that some dispositions (like "hearing_impaired") were kind of metadata switches that can be turned on/off for any type of stream inside any container. Part of the confusion arises from lack of documentation and the fact that ffprobe always returns ALL disposition types irrespective of stream or container, but it should probably only return the dispositions that are applicable to a particular stream type inside a particular container.

Now I realize that the ability to set disposition types depends on the container (and maybe on the stream type?). As far as I can gather after further investigating about this by searching through ffmpeg-devel and trying to figure out the relevant parts of the source code, it seems that the dispositions "clean_effects", "hearing_impaired", "visual_impaired" (as an example) correspond to the audio_type field of the MPEG-2 ISO 639 language descriptor.

But I've tried setting these three flags to AC3 and mp2 audio streams inside different .ts containers, and all of them failed (disposition settings were ignored). So it seems this isn't just about Matroska, because I can't set any disposition of a stream other than Forced or Default in any container that I tried so far.

Last edited 15 months ago by droid-xx (previous) (diff)

comment:4 by mkver, 15 months ago

The mpegts muxer code shows that these dispositions are only used when the track has a language (after all, it is for the MPEG-2 ISO 639 language descriptor).

Also notice that lots of muxers also ignore metadata or only care about a few metadata entries (because the format doesn't support generic metadata or because it is unimplemented).

in reply to:  4 comment:5 by droid-xx, 15 months ago

Replying to mkver:

after all, it is for the MPEG-2 ISO 639 language descriptor

You're right, lol. I can set these dispositions fine when I also set a language for the specified track.

I'm looking forward to using the disposition flags that are now supported in .mkv containers after your patch is accepted (in which case I guess this ticket can be closed).

comment:6 by mkver, 15 months ago

Resolution: fixed
Status: newclosed

Implemented in 51e10677291863e496cabcc71fe871628e869f2e, f9ceb18f3b26d792522536d32838c6795b8df20d and a few other commits as far as the Matroska file format allows.

comment:7 by mkver, 15 months ago

Component: ffmpegavformat
Keywords: ffmpeg removed

comment:8 by Carl Eugen Hoyos, 15 months ago

Keywords: mkv added; metadata removed
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.