[FFmpeg-user] change defaults for subtitle streams

Peter White peter.white at posteo.net
Fri Aug 12 13:41:52 EEST 2016


12.08.2016 10:34, Mikołaj Machowski:
 >> 11.08.2016 14:23, Mikołaj Machowski:
 >>> I have video with four streams: 0:0 video, 0:1 audio, 0:2 sub1, 0:3 
sub2
 >
 >>> Result of normal settings is that both subtitle streams are default
 >
 >> Which container or file type is this? I know for certain that multiple
 >> default streams of the same kind are not allowed in the matroska (.mkv)
 >> format.
 >
 >>> and  various players are interpreting this differently eg. ffplay 
is loading
 >>> sub1 because this is first, vlc is loading sub2 because this is the 
last
 >>> with default flag.
 >
 >> Case in point. This file should have never existed. ;)
 >
 > Well, relevant output of ffprobe:
 >
 > Input #0, matroska,webm, from 'dep5919_2.mkv':
 >   Metadata:
 >     ENCODER         : Lavf57.41.100

OK, so it was ffmpeg or some tool using it as a backend, apparently.

 > Don't remember exactly how I created it but it was something like:
 >
 > $ ffmpeg -i VTS_01_1.VOB -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:a 
flac -c:v ffv1 -c:s copy output.mkv
 >
 > There was no default flag on any sub stream when doing ffprobe on it.

 From my understanding, ffmpeg does /not/ set a default stream in
matroska. Here is some more info by, which I found yesterday, when I
was investigating the mentioned curiosities:

https://trac.ffmpeg.org/ticket/2402#comment:1

So, if I understand that comment correctly, ffprobe just makes it look
like all the streams have the flag set, when really none of them has
it.
I do agree that this is a bit confusing, but would not know how to
make this more in ffprobe's output.

 >>> How to 'undefault' one of streams and add descriptions?
 >
 >> You need to change the "disposition", like this:
 >
 >> $ ffmpeg -i bad_file.mkv -c copy -map 0 -disposition:s:1 -default 
good_file.mkv
 >
 > This one didn't work for me

Then it would be nice of you to provide the console output and the
exact command. Also, your ffmpeg version is of interest, but it is
included in the console output, anyway.

 > had to recode from the source but with your example could do it
 > properly.

Now I am confused. Did or did it not work? You seem to be referring to
the same example.
But, actually I am not quite sure now, maybe /I/ have got it wrong. I
only read above trac comment after I send my mail. Now, when I do:

$ ffmpeg -i no_default.mka -c copy -map 0 -disposition:a:1 +default 
a1_is_default.mka
ffmpeg version N-81313-g329ae0b Copyright (c) 2000-2016 the FFmpeg 
developers
   built with gcc 4.9.2 (Debian 4.9.2-10)
   configuration: --extra-cflags='-march=native' --enable-shared 
--enable-gpl --enable-nonfree --enable-libfdk-aac 
--disable-runtime-cpudetect --enable-libx264 --enable-libvorbis 
--enable-gnutls --enable-opengl --enable-libopus --enable-libfreetype 
--enable-libfontconfig --enable-libfribidi --enable-libsoxr 
--enable-libzvbi --enable-libmp3lame
   libavutil      55. 28.100 / 55. 28.100
   libavcodec     57. 51.100 / 57. 51.100
   libavformat    57. 46.100 / 57. 46.100
   libavdevice    57.  0.102 / 57.  0.102
   libavfilter     6. 50.100 /  6. 50.100
   libswscale      4.  1.100 /  4.  1.100
   libswresample   2.  1.100 /  2.  1.100
   libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from 'no_default.mka':
   Metadata:
     ENCODER         : Lavf57.46.100
   Duration: 00:05:18.67, start: -0.007000, bitrate: 185 kb/s
     Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp (default)
     Metadata:
     [...]
     Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
     [...]
[matroska @ 0x1221920] Using AVStream.codec to pass codec parameters to 
muxers is deprecated, use AVStream.codecpar instead.
     Last message repeated 1 times
Output #0, matroska, to 'a1_is_default.mka':
   Metadata:
     encoder         : Lavf57.46.100
     Stream #0:0: Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 
Hz, stereo (default)
     [...]
     Stream #0:1: Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 
Hz, stereo (default)
     [...]
Stream mapping:
   Stream #0:0 -> #0:0 (copy)
   Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
size=    7225kB time=00:05:18.66 bitrate= 185.7kbits/s speed= 139x
video:0kB audio:7007kB subtitle:0kB other streams:0kB global headers:0kB 
muxing overhead: 3.099252%

ffmpeg basically does nothing, as can be seen by both output streams
still showing as "default", which really means none have this set.

OTOH, setting this to "not default", which I understand is different
from unsetting seems to to work:

$ ffmpeg -y -hide_banner -i no_default.mka -c copy -map 0 
-disposition:a:1 -default a1_is_default.mka
Input #0, matroska,webm, from 'no_default.mka':
   Metadata:
     ENCODER         : Lavf57.46.100
   Duration: 00:05:18.67, start: -0.007000, bitrate: 185 kb/s
     Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp (default)
     Metadata:
     [...]
     Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
     [...]
[matroska @ 0x8fa960] Using AVStream.codec to pass codec parameters to 
muxers is deprecated, use AVStream.codecpar instead.
Output #0, matroska, to 'a1_is_default.mka':
   Metadata:
     encoder         : Lavf57.46.100
     Stream #0:0: Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 
Hz, stereo (default)
     Metadata:
     [...]
     Stream #0:1: Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 
Hz, stereo
     Metadata:
     [...]
Stream mapping:
   Stream #0:0 -> #0:0 (copy)
   Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
size=    7225kB time=00:05:18.66 bitrate= 185.7kbits/s speed= 139x
video:0kB audio:7007kB subtitle:0kB other streams:0kB global headers:0kB 
muxing overhead: 3.099294%

As tool to check this, I use the header editor of mmg, which is part
of mkvtoolnix. In the first case it still tells me, that no stream has
the default flag set. In the latter case it says that, audio stream 1
indeed is set to "no" as value for default.
I think this might be a bug. But, since you want to set tracks as not
default, this should not concern you. Maybe this warrants a new topic
on this list, not sure. Have to check my own ffmpeg version first.
Maybe I messed something up.

 > '-disposition' still isn't documented on ffmpeg.org. Grrr.

Yes, it does lack documentation, but at least

$ ffmpeg -h full

mentions it. But if one has no idea, what "disposition" is supposed to
mean, then it really does not help much. But a web search helped me
the other day. ;)

 > Interesting that when specifying default for one stream, defaults
 > were removed from all other (added some metadata):

That should also be explained by above comment on the bug tracker.

 >> More generally it goes like:
 >
 >> $ ffmpeg -i input -c copy -map 0 -disposition:stream_spec flags output
 >
 >> More info on stream_spec can be found in the "Stream specifiers"
 >> section of the ffmpeg manual.
 >
 >> So, this also works:
 >> $ ffmpeg -i input -c copy -map 0 -disposition:s:1 +default+forced output
 >
 > Where can I read about '+' stuff?

I don't know if it is mentioned explicitly in the docs. I just derived
this from the examples for -fflags and some prior computer science
knowledge. In short, flags are just bits in a binary "word" or
bit-field. Say, "default" is bit 0, counted from the right and
"forced" is bit 1 and the "word" is just one byte. Then setting
+default+forced is simply:

0000 0001 ("default")
+
0000 0010 ("forced")
=
0000 0011 (default+forced)

"-default" corresponds to setting that bit to 0.

 > Thank you very much for your help.

You are welcome. I do hope, though that I did not cause more
confusion. :)

But, long story short, I don't think ffmpeg is the right tool for this
job, which really is only metadata editing. Since there is no way of
just manipulatiing such data without rewriting the whole file, I think
you should consider other options. Use the right tool for the job.
ffmpeg is great at transcoding, muxing etc. but it is limited to
writing a new file, basically.
A note to everone else, who might think of taking offense with above
paragraph, it is not in any way meant that way. As I said, ffmpeg is a
great tool to get from file A to file B. But when file B just needs
some tweaking it is incapable of doing so without creating a file C.
Other tools specifically designed for metadata editing can directly
write to file B. IMHO, that is the way it should be done in this
particular case.


 > ps. I don't receive mails from 'my' thread so this message may appear 
as separate thread.

Yes, I noticed. Please change your list settings or use the link in
the archive, i.e.:

https://ffmpeg.org/pipermail/ffmpeg-user/2016-August/033175.html

Right below the subject line is the link, beside the name of the
sender. When you click that, your mail client also sets the reference
header, so the list knows which thread you are responding to.


Best,
Peter


More information about the ffmpeg-user mailing list