From a82f6e6a6db2f59f484bf83790b7a78c452bdc5c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 30 Aug 2024 10:33:01 +0200 Subject: [PATCH] mkvmerge: chapters: support specifying MPLS with `--chapters` Fixes/implements #3735 --- NEWS.md | 4 ++++ src/common/chapters/bluray.cpp | 17 +++++++++++++++++ src/common/chapters/bluray.h | 1 + src/common/chapters/chapters.cpp | 11 +++++++++++ src/common/chapters/chapters.h | 1 + 5 files changed, 34 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4dd3cde18..397cd3e50 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ * MKVToolNix GUI: jobs: the status bar now differentiates between numbers of warnings/errors that occurred in the current session and those that occurred before the current session. Implements #3732. +* mkvmerge: chapters: added support for specifying MPLS files with + `--chapters`, too, not just as regular source files. The documentation + stated this was possible already, but that wasn't actually the + case. Implements/fixes #3735. ## Bug fixes diff --git a/src/common/chapters/bluray.cpp b/src/common/chapters/bluray.cpp index 4d60fc6b7..060240e2c 100644 --- a/src/common/chapters/bluray.cpp +++ b/src/common/chapters/bluray.cpp @@ -16,6 +16,8 @@ #include "common/chapters/chapters.h" #include "common/construct.h" #include "common/ebml.h" +#include "common/hacks.h" +#include "common/mm_file_io.h" #include "common/unique_numbers.h" namespace mtx::chapters { @@ -66,4 +68,19 @@ convert_mpls_chapters_kax_chapters(mtx::bluray::mpls::chapters_t const &mpls_cha return kax_chapters; } +std::shared_ptr +maybe_parse_bluray(std::string const &file_name, + mtx::bcp47::language_c const &language) { + + mm_file_io_c in{file_name}; + auto parser = mtx::bluray::mpls::parser_c{}; + + parser.enable_dropping_last_entry_if_at_end(!mtx::hacks::is_engaged(mtx::hacks::KEEP_LAST_CHAPTER_IN_MPLS)); + + if (parser.parse(in)) + return mtx::chapters::convert_mpls_chapters_kax_chapters(parser.get_chapters(), language, g_chapter_generation_name_template.get_translated()); + + return {}; +} + } diff --git a/src/common/chapters/bluray.h b/src/common/chapters/bluray.h index 9aa4dcd76..04b69eff8 100644 --- a/src/common/chapters/bluray.h +++ b/src/common/chapters/bluray.h @@ -21,5 +21,6 @@ class KaxChapters; namespace mtx::chapters { std::shared_ptr convert_mpls_chapters_kax_chapters(mtx::bluray::mpls::chapters_t const &chapters, mtx::bcp47::language_c const &main_language, std::string const &name_template = {}); +std::shared_ptr maybe_parse_bluray(std::string const &file_name, mtx::bcp47::language_c const &language); } diff --git a/src/common/chapters/chapters.cpp b/src/common/chapters/chapters.cpp index 3d37af696..c5b0509b3 100644 --- a/src/common/chapters/chapters.cpp +++ b/src/common/chapters/chapters.cpp @@ -22,6 +22,7 @@ #include "common/bcp47.h" #include "common/chapters/chapters.h" +#include "common/chapters/bluray.h" #include "common/chapters/dvd.h" #include "common/construct.h" #include "common/container.h" @@ -548,6 +549,16 @@ parse(const std::string &file_name, } #endif + auto parsed_bluray_chapters = maybe_parse_bluray(file_name, language); + if (parsed_bluray_chapters) { + unify_legacy_and_bcp47_languages_and_countries(*parsed_bluray_chapters); + + if (format) + *format = format_e::bluray; + + return parsed_bluray_chapters; + } + mm_text_io_c in(std::make_shared(file_name)); auto parsed_chapters = parse(&in, min_ts, max_ts, offset, language, charset, exception_on_error, format, tags); diff --git a/src/common/chapters/chapters.h b/src/common/chapters/chapters.h index 7e973946d..f9418fcb9 100644 --- a/src/common/chapters/chapters.h +++ b/src/common/chapters/chapters.h @@ -56,6 +56,7 @@ enum class format_e { cue, ffmpeg_meta, dvd, + bluray, }; mtx::chapters::kax_cptr