Opened 12 years ago

Closed 8 years ago

#2402 closed enhancement (fixed)

FFmpeg marks no subtitles in mkv files as default

Reported by: someuser Owned by:
Priority: wish Component: ffmpeg
Version: git-master Keywords: mkv
Cc: zagser168@yandex.ru Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Summary of the bug:
Some related discussion was in ticket #1815.

When creating a Matroska / mkv file with FFmpeg with several subtitle streams all of them are marked as default and there seems to be no way to disable setting of the default flag for any of the subtitle streams.

Below is an example with the presumably correct metadata identifier default-flag=0 in use.

With both subtitles marked as default VLC shows the last subtitle stream but MPC-HC shows the first one (provided that no subtitle language preference has been set).

How to reproduce:

> ./ffmpeg -fflags +genpts -i test.mp4 -i test-en.srt -i test-fr.srt -c:a copy -c:v copy -c:s copy -metadata:s:s:0 language=eng -metadata:s:s:1 language=fra -metadata:s:s:1 default-flag=0 -map 0:0 -map 0:1 -map 1:0 -map 2:0 test.mkv
ffmpeg version N-51211-ge0e8c20 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 22 2013 08:56:38 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 22.101 / 52. 22.101
  libavcodec     55.  1.100 / 55.  1.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 48.100 /  3. 48.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.59.106
  Duration: 00:00:10.05, start: 0.021333, bitrate: 1257 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 576x324 [SAR 1:1 DAR 16:9], 1132 kb/s, 23.98 fps, 23.98 tbr, 11988 tbn, 47.95 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 119 kb/s
    Metadata:
      handler_name    : SoundHandler
[srt @ 0272d9e0] Estimating duration from bitrate, this may be inaccurate
Input #1, srt, from 'test-en.srt':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Subtitle: subrip
[srt @ 02861780] Estimating duration from bitrate, this may be inaccurate
Input #2, srt, from 'test-fr.srt':
  Duration: N/A, bitrate: N/A
    Stream #2:0: Subtitle: subrip
Output #0, matroska, to 'test.mkv':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.0.100
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 576x324 [SAR 1:1 DAR 16:9], q=2-31, 1132 kb/s, 23.98 fps, 1k tbn, 11988 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, 119 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Subtitle: subrip
    Stream #0:3(fra): Subtitle: subrip
    Metadata:
      default-flag    : 0
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #1:0 -> #0:2 (copy)
  Stream #2:0 -> #0:3 (copy)
Press [q] to stop, [?] for help
frame=  241 fps=0.0 q=-1.0 Lsize=    1542kB time=00:00:10.04 bitrate=1256.9kbits/s
video:1389kB audio:146kB subtitle:0 global headers:0kB muxing overhead 0.399761%
> ffprobe -i test.mkv -loglevel 0 -show_streams
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=125/5994
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=576
height=324
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=40
timecode=N/A
is_avc=1
nal_length_size=4
id=N/A
r_frame_rate=2997/125
avg_frame_rate=2997/125
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:LANGUAGE=und
TAG:HANDLER_NAME=VideoHandler
[/STREAM]
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=2
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:LANGUAGE=und
TAG:HANDLER_NAME=SoundHandler
[/STREAM]
[STREAM]
index=2
codec_name=subrip
codec_long_name=SubRip subtitle
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:LANGUAGE=eng
[/STREAM]
[STREAM]
index=3
codec_name=subrip
codec_long_name=SubRip subtitle
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:LANGUAGE=fra
TAG:DEFAULT-FLAG=0
[/STREAM]
>

Change History (6)

comment:1 by Carl Eugen Hoyos, 12 years ago

Analyzed by developer: set
Component: undeterminedFFmpeg
Priority: minorwish
Reproduced by developer: set
Status: newopen
Summary: FFmpeg marks all subtitles in mkv files as defaultFFmpeg marks no subtitles in mkv files as default
Type: defectenhancement

None of your input subtitle streams is marked as default, current FFmpeg therefore does not write the default flag for any of the subtitle tracks. The Matroska specification - http://matroska.org/technical/specs/index.html (search for FlagDefault) - specifies that the value for the default flag is "default" if nothing is specified, the demuxer therefore marks all subtitle tracks as "default".

What is missing afaict is a possibility for the user to mark streams as default streams, an alternative is to always set the first stream as default in the Matroska muxer, I am not completely convinced that this is the best solution, consider sending a patch if that is what you want.

comment:2 by Carl Eugen Hoyos, 12 years ago

Keywords: mkv added

in reply to:  1 ; comment:3 by someuser, 12 years ago

Replying to cehoyos:

None of your input subtitle streams is marked as default, current FFmpeg therefore does not write the default flag for any of the subtitle tracks. The Matroska specification - http://matroska.org/technical/specs/index.html (search for FlagDefault) - specifies that the value for the default flag is "default" if nothing is specified, the demuxer therefore marks all subtitle tracks as "default".

Ok, thanks for this background information, I was looking at the above output and saw DISPOSITION:default=1 and also in ffmpeg -i test.mkv output there is:

Stream #0:2(eng): Subtitle: subrip (default)
Stream #0:3(fra): Subtitle: subrip (default)

What is missing afaict is a possibility for the user to mark streams as default streams, an alternative is to always set the first stream as default in the Matroska muxer, I am not completely convinced that this is the best solution,

For me as a user the ability to mark streams as default streams sounds like an ideal solution, although forcing the first one being the default one would be ok'ish, too.

consider sending a patch if that is what you want.

I am a user unfortunately not a developer so I tried to do my best with home work wrt googling, reading documents, checking for duplicate tickets, etc and since I couldn't find any clear answers I wanted to file this ticket to serve as a note for other users and developers alike.

Thanks.

in reply to:  3 comment:4 by Carl Eugen Hoyos, 12 years ago

Replying to someuser:

Replying to cehoyos:

None of your input subtitle streams is marked as default, current FFmpeg therefore does not write the default flag for any of the subtitle tracks. The Matroska specification - http://matroska.org/technical/specs/index.html (search for FlagDefault) - specifies that the value for the default flag is "default" if nothing is specified, the demuxer therefore marks all subtitle tracks as "default".

Ok, thanks for this background information, I was looking at the above output and saw DISPOSITION:default=1 and also in ffmpeg -i test.mkv output there is:

Stream #0:2(eng): Subtitle: subrip (default)
Stream #0:3(fra): Subtitle: subrip (default)

Allow me to repeat in case I wasn't clear enough:
The muxer does not write any default information in your command line, the specification forces the demuxer to report "default" for all streams (because no default information was written).

comment:5 by zagser168, 11 years ago

Cc: zagser168@yandex.ru added

comment:6 by c-14, 8 years ago

Resolution: fixed
Status: openclosed

The ability to mark specific streams as default was added in 85d7e02e4af4e6250be77ec43a72807d029a0061

Note: See TracTickets for help on using tickets.