Opened 4 years ago

Closed 4 years ago

#8416 closed defect (fixed)

disposition option ignored when muxing hls from a web url and srt subtitle file together in an mkv container

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

Description

Summary of the bug:
I am downloading a hls video and muxing it together with a local srt subtitle file into an mkv container. I have tried using the -disposition option to prevent the subtitles from being flagged as default subtitles, but the the -disposition option is ignored.

How to reproduce:
This command results in an mkv with the subtitles flagged as default despite using the -disposition option to set the default flag as false

% ffmpeg -i 'http://some_video_site/somevideo.m3u8' -i local_subtitles_file.srt  -vcodec copy -acodec copy -scodec srt -disposition:s -default -metadata:s:s:0 language=eng output.mkv

However, I can change the subtitle stream's default flag to false by running the following command on the output.mkv file produced by the command above.

% ffmpeg -i output.mkv -codec copy -disposition:s -default no_default_subtitles.mkv

The resulting file no_default_subtitles.mkv will play without the subtitles being displayed by default. ffprobe confirms that the subtitles are not default.

Interestingly, I have also found that if I first download the video to an mkv container and then mux that mkv file with the subtitle file into a new mkv file with the following commands, the subtitles are not marked as default even though the -disposition option is not used.

% ffmpeg -i 'http://some_video_site/somevideo.m3u8' -c copy some_local_video_file.mkv
% ffmpeg -i some_local_video_file.mkv -i some_local_subtitles.srt -vcodec copy -acodec copy -scodec srt -metadata:s:s:0 language=eng no_default_subtitles.mkv

It is odd to me that the above command results in an mkv in which the subtitles are not flagged as default, but the command that downloads the video and adds the subtitles does not even though that command explicitly sets the default flag to false.

ffmpeg version info:

ffmpeg version 4.2.1-2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Debian 9.2.1-15)
configuration: --prefix=/usr --extra-version=2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

Change History (5)

comment:1 by mkver, 4 years ago

Component: undeterminedavformat
Keywords: mkv added; default subtitle subtitles removed

This is very related to #8173: The Matroska muxer first looks for whether any input stream has disposition default; if not, it flags every track as default track (if there is more than one track of a given kind, this will result in several tracks of this kind being marked as default). The reason is that lots of other formats don't have the concept of default tracks, so the input streams are often not flagged as such (even when there is only one track of a kind in which case treating this track as default by default even when it does not have the disposition default explicitly set makes sense).

comment:2 by bgx90, 4 years ago

Yes, the Matroska muxer will set all tracks of a type to default when no track has the default flag explicitly set to 0 or 1 via the disposition option. However, The option used in #8173(ticket) is -disposition[:stream_specifier] 0 which does not do the same thing as the option -disposition:s -default which is what I am using. -disposition:s -default explicitly sets the default flag to 0 (false); -disposition[:stream_specifier] 0 removes the dispositions entirely.

If I have an mkv file (input.mkv) with a single subtitle stream and that subtitle stream is marked as default, I can create a new mkv with the subtitle stream not marked as default with this command:
% ffmpeg -i input.mkv -codec copy -disposition:s -default no_default_subtitles.mkv

However, when I mux a local mkv and a local subtitle file together, I can successfully create a new mkv with no default subtitle whether or not I include -disposition:s -default. I would have expected that -disposition:s -default would be required in this case to prevent the subtitle stream from being flagged as default. This behavior seems strange, but is not a problem for me.

The problem I am having is that when I try to mux streams coming from a web url in TS segments with the local subtitle file the subtitle track gets flagged as default even though I include the option -disposition:s -default.

In short, the question is why do both of these commands result in mkv files that do not mark the subtitle stream as default
% ffmpeg -i some_local_video_file.mkv -i some_local_subtitles.srt -vcodec copy -acodec copy -scodec srt -metadata:s:s:0 language=eng no_default_subtitles.mkv

% ffmpeg -i some_local_video_file.mkv -i some_local_subtitles.srt -vcodec copy -acodec copy -scodec srt -disposition:s -default -metadata:s:s:0 language=eng no_default_subtitles.mkv

while this command results in an mkv file that marks the subtitle stream as default even thought the default flag is explicitly set to 0 (false) by the disposition option and the only difference is that the audio and video streams are being downloaded from a web url in TS packets instead of coming from a local mkv file like in the two commands above
% ffmpeg -i 'http://some_video_site/somevideo.m3u8' -i local_subtitles_file.srt -vcodec copy -acodec copy -scodec srt -disposition:s -default -metadata:s:s:0 language=eng output.mkv

comment:3 by mkver, 4 years ago

Sorry, I have not noticed that you have answered again: Most Matroska files contain a track that is flagged as default. This makes the Matroska muxer set the dispositions as they are in the input. If no input stream has default disposition set, the Matroska muxer makes every stream a default stream (even multiple streams of the same kind). This behaviour is obviously so because lots of other formats don't even have the concept of default streams, so it is not uncommon for no stream to have this set, whereas it is common to set this for Matroska (but setting it for all streams in a Matroska file is just wrong and will be changed).

So here is a workaround for you: Set the video and/or the audio track from your hls input as default.

comment:4 by Carl Eugen Hoyos, 4 years ago

Version: 4.2git-master

comment:5 by mkver, 4 years ago

Resolution: fixed
Status: newclosed

Fixed in e3c54b549abf2798422245582c0ed775c894ddeb. The infer_no_subs option does what you want.

Note: See TracTickets for help on using tickets.