From a310e7d120682d86a5b11066d729d8f0796127e4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 29 Jun 2020 21:02:36 +0200 Subject: [PATCH] Matroska reader: fix `default track` flag handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- NEWS.md | 11 +++++++++++ src/input/r_matroska.cpp | 11 ++++++----- tests/results.txt | 1 + ...efault_track_forced_off_vs_default_by_type.rb | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100755 tests/test-699default_track_forced_off_vs_default_by_type.rb diff --git a/NEWS.md b/NEWS.md index 85a5004a0..a069160e5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index 010c37e3e..ea52668a7 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -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); diff --git a/tests/results.txt b/tests/results.txt index 640d850c0..0e0b814c3 100644 --- a/tests/results.txt +++ b/tests/results.txt @@ -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 diff --git a/tests/test-699default_track_forced_off_vs_default_by_type.rb b/tests/test-699default_track_forced_off_vs_default_by_type.rb new file mode 100755 index 000000000..72e83997e --- /dev/null +++ b/tests/test-699default_track_forced_off_vs_default_by_type.rb @@ -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