Matroska reader: fix default track flag handling

Let's take a Matroska file with a subtitle track with its `default
track` set to `on`. When you remux that file, forcing that flag to off
via `--default-track …:no`, the first other track of the same
type (subtitles) that is read from a container which does not provide
such `default track` information (e.g. an SRT file) should have its
`default track` flag set.

Before this change this wasn't the case; the track from the SRT would
have its flag set to `no`. The Matroska reader was always signalling
"default track = yes` at the container level to the packetizer, even
if it was overridden via command line options. The flag would still be
set to `no` in the output file, but the fact that there was a `yes` at
the container level prevented `mkvmerge` from considering other tracks
which only had a priority of `track type`.

Fixes #2863.
This commit is contained in:
Moritz Bunkus 2020-06-29 21:02:36 +02:00
parent 4e2530afca
commit a310e7d120
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
4 changed files with 34 additions and 5 deletions

11
NEWS.md
View File

@ -1,3 +1,14 @@
# Version ?
## Bug fixes
* mkvmerge: Matroska reader: when reading tracks (e.g. a subtitle track) from
Matroska files with their `default track` flag set to `yes`, and when
overwriting those via the command line to `no`, `mkvmerge` would not promote
additional tracks of the same type from other files (e.g. another subtitle
track from an SRT file). Fixes #2863.
# Version 48.0.0 "Sick Of Losing Soulmates" 2020-06-27
## New features and enhancements

View File

@ -1649,11 +1649,12 @@ kax_reader_c::set_packetizer_headers(kax_track_t *t) {
if (m_appending)
return;
if (t->default_track)
PTZR(t->ptzr)->set_as_default_track(t->type == 'v' ? DEFTRACK_TYPE_VIDEO : t->type == 'a' ? DEFTRACK_TYPE_AUDIO : DEFTRACK_TYPE_SUBS, DEFAULT_TRACK_PRIORITY_FROM_SOURCE);
else if (!PTZR(t->ptzr)->m_ti.m_default_track.has_value())
PTZR(t->ptzr)->m_ti.m_default_track = false;
if (!PTZR(t->ptzr)->m_ti.m_default_track.has_value()) {
if (t->default_track)
PTZR(t->ptzr)->set_as_default_track(t->type == 'v' ? DEFTRACK_TYPE_VIDEO : t->type == 'a' ? DEFTRACK_TYPE_AUDIO : DEFTRACK_TYPE_SUBS, DEFAULT_TRACK_PRIORITY_FROM_SOURCE);
else
PTZR(t->ptzr)->m_ti.m_default_track = false;
}
if (t->forced_track && !PTZR(t->ptzr)->m_ti.m_forced_track.has_value())
PTZR(t->ptzr)->set_track_forced_flag(true);

View File

@ -544,3 +544,4 @@ T_695mpeg_ts_single_h264_frame_with_unbounded_pes_size:a97c491d719a6228d593e6d67
T_696wavpack5:167606e4e11fef79a9cb859a371d4d8a-009b8b5a53f51ddf0f8fd3be3bf808cb-167606e4e11fef79a9cb859a371d4d8a:passed:20200617-144644:0.079896556
T_697dts_es_xch:true:passed:20200622-160456:0.0
T_698ac3_dolby_surround_ex:true-true-true:passed:20200622-173931:0.051167592
T_699default_track_forced_off_vs_default_by_type:59aea3a8b7c10b1e64e6e241f2dc979c-true-59aea3a8b7c10b1e64e6e241f2dc979c-true-c4e85aed908bbe688fe6949c442cdbba-true:passed:20200629-201706:0.073934952

View File

@ -0,0 +1,16 @@
#!/usr/bin/ruby -w
# T_699default_track_forced_off_vs_default_by_type
describe "mkvmerge / Matroska file with 'default track' set, overwritten on command line, track from additional SRT file should become default"
file_names = "data/mkv/sub-is-default.mks data/subtitles/srt/ven.srt"
specs = [ [ "", true, false ], [ "--default-track 0:yes", true, false ], [ "--default-track 0:no", false, true ] ]
specs.each do |spec|
test_merge file_names, :args => spec[0], :keep_tmp => true
test "#{spec}" do
json = identify_json(tmp)
(json["tracks"][0]["properties"]["default_track"] == spec[1]) && (json["tracks"][1]["properties"]["default_track"] == spec[2])
end
end