From 2dd33027fdfa7f045fa9846286ebe3c65e60c1d9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 27 Apr 2018 23:14:13 +0200 Subject: [PATCH] track statistics tags: don't write _STATISTICS_WRITING_DATE_UTC with --no-date Fixes #2286. --- NEWS.md | 3 +++ src/common/track_statistics.cpp | 17 ++++++++++------- src/common/track_statistics.h | 2 +- src/merge/cluster_helper.cpp | 4 +++- tests/results.txt | 1 + tests/test-640no_date.rb | 5 +++++ 6 files changed, 23 insertions(+), 9 deletions(-) create mode 100755 tests/test-640no_date.rb diff --git a/NEWS.md b/NEWS.md index f639e491c..e8744430e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,9 @@ memory leaks. * mkvextract: fixed a crash when mkvextract with a non-Matroska file as the source file. Fixes #2281. +* mkvmerge: track statistics tags: if writing the `Date` element is + deactivated via `--no-date`, the `_STATISTICS_WRITING_DATE_UTC` isn't + written either anymore. Fixes #2286. ## Build system changes diff --git a/src/common/track_statistics.cpp b/src/common/track_statistics.cpp index da7fdb4f9..2d68d02dd 100644 --- a/src/common/track_statistics.cpp +++ b/src/common/track_statistics.cpp @@ -19,11 +19,10 @@ void track_statistics_c::create_tags(KaxTags &tags, std::string const &writing_app, - boost::posix_time::ptime const &writing_date) + boost::optional writing_date) const { - auto writing_date_str = !writing_date.is_not_a_date_time() ? mtx::date_time::to_string(writing_date, "%Y-%m-%d %H:%M:%S") : "1970-01-01 00:00:00"; - auto bps = get_bits_per_second(); - auto duration = get_duration(); + auto bps = get_bits_per_second(); + auto duration = get_duration(); mtx::tags::remove_simple_tags_for(tags, m_track_uid, "BPS"); mtx::tags::remove_simple_tags_for(tags, m_track_uid, "DURATION"); @@ -39,8 +38,12 @@ track_statistics_c::create_tags(KaxTags &tags, mtx::tags::set_simple(*tag, "NUMBER_OF_FRAMES", ::to_string(m_num_frames)); mtx::tags::set_simple(*tag, "NUMBER_OF_BYTES", ::to_string(m_num_bytes)); - mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_APP", writing_app); - mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_DATE_UTC", writing_date_str); - mtx::tags::set_simple(*tag, "_STATISTICS_TAGS", "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES"); + mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_APP", writing_app); + if (writing_date) { + auto writing_date_str = !writing_date->is_not_a_date_time() ? mtx::date_time::to_string(*writing_date, "%Y-%m-%d %H:%M:%S") : "1970-01-01 00:00:00"; + mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_DATE_UTC", writing_date_str); + } + + mtx::tags::set_simple(*tag, "_STATISTICS_TAGS", "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES"); } diff --git a/src/common/track_statistics.h b/src/common/track_statistics.h index ed53c6ba9..9068fc66b 100644 --- a/src/common/track_statistics.h +++ b/src/common/track_statistics.h @@ -87,5 +87,5 @@ public: % (bps ? *bps : -1)).str(); } - void create_tags(KaxTags &tags, std::string const &writing_app, boost::posix_time::ptime const &writing_date) const; + void create_tags(KaxTags &tags, std::string const &writing_app, boost::optional writing_date) const; }; diff --git a/src/merge/cluster_helper.cpp b/src/merge/cluster_helper.cpp index 7b5034372..180a346dd 100644 --- a/src/merge/cluster_helper.cpp +++ b/src/merge/cluster_helper.cpp @@ -699,10 +699,12 @@ void cluster_helper_c::create_tags_for_track_statistics(KaxTags &tags, std::string const &writing_app, boost::posix_time::ptime const &writing_date) { + auto actual_writing_date = g_write_date ? boost::optional{writing_date} : boost::optional{}; + for (auto const &ptzr : g_packetizers) { auto track_uid = ptzr.packetizer->get_uid(); - m->track_statistics[track_uid].set_track_uid(track_uid).create_tags(tags, writing_app, writing_date); + m->track_statistics[track_uid].set_track_uid(track_uid).create_tags(tags, writing_app, actual_writing_date); } m->track_statistics.clear(); diff --git a/tests/results.txt b/tests/results.txt index 040bd0f09..92490abb9 100644 --- a/tests/results.txt +++ b/tests/results.txt @@ -485,3 +485,4 @@ T_636flac_with_id3_tags:c8b37897660d88038c4e6f401fe6c94c:passed:20180310-182917: T_637mp4_8_channels_in_track_headers_but_7_in_codec_specific_config:true:passed:20180322-222201:0.012853536 T_638av1_ivf_webm:75abc9d1c93b75f11f2cde679007988f-4c0b2d5332293c142c9ccff0103f5c00-7c939fffa12bc12aa4051cd037b82676-6735876d7334af154ff61994e9664239:passed:20180401-164905:0.057966018 T_639vobsub_missing_duration_in_matroska:1da346761ddede951b1f2f5f11cd3f69:passed:20180401-193013:0.014669303 +T_640no_date:20fbba5a79a436caa36582e7675c1038:passed:20180427-231324:0.011724657 diff --git a/tests/test-640no_date.rb b/tests/test-640no_date.rb new file mode 100755 index 000000000..0109585d1 --- /dev/null +++ b/tests/test-640no_date.rb @@ -0,0 +1,5 @@ +#!/usr/bin/ruby -w + +# T_640no_date +describe "mkvmerge / don't write the date" +test_merge "data/subtitles/srt/ven.srt", :args => "--no-date"