From 4e9a15d558ecca660eb74f54b693d1e4a3aa7381 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 9 Apr 2021 00:03:35 +0200 Subject: [PATCH] Extract audio/subtitle language from imported DCPs. --- cscript | 4 ++-- src/lib/dcp_content.cc | 20 ++++++++++++-------- src/lib/dcp_examiner.cc | 16 +++++++++++++++- src/lib/dcp_examiner.h | 10 ++++++++++ 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/cscript b/cscript index a80c220dc..58f95dc91 100644 --- a/cscript +++ b/cscript @@ -385,8 +385,8 @@ def dependencies(target, options): # Use distro-provided FFmpeg on Arch deps = [] - deps.append(('libdcp', '3a328b6')) - deps.append(('libsub', '2bbddc6')) + deps.append(('libdcp', '4552587')) + deps.append(('libsub', '9901351')) deps.append(('leqm-nrt', '131f971')) deps.append(('rtaudio', 'f619b76')) # We get our OpenSSL libraries from the environment, but we diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 42c371ee5..0da42502f 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -242,6 +242,7 @@ DCPContent::examine (shared_ptr film, shared_ptr job) boost::mutex::scoped_lock lm (_mutex); audio = make_shared(this); } + audio->set_language (examiner->audio_language()); auto as = make_shared(examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels()); audio->set_stream (as); auto m = as->mapping (); @@ -262,14 +263,17 @@ DCPContent::examine (shared_ptr film, shared_ptr job) } list> new_text; - for (int i = 0; i < static_cast(TextType::COUNT); ++i) { - for (int j = 0; j < examiner->text_count(static_cast(i)); ++j) { - auto c = make_shared(this, static_cast(i), static_cast(i)); - if (i == static_cast(TextType::CLOSED_CAPTION)) { - c->set_dcp_track (examiner->dcp_text_track(j)); - } - new_text.push_back (c); - } + + for (int i = 0; i < examiner->text_count(TextType::OPEN_SUBTITLE); ++i) { + auto c = make_shared(this, TextType::OPEN_SUBTITLE, TextType::OPEN_SUBTITLE); + c->set_language (examiner->open_subtitle_language()); + new_text.push_back (c); + } + + for (int i = 0; i < examiner->text_count(TextType::CLOSED_CAPTION); ++i) { + auto c = make_shared(this, TextType::CLOSED_CAPTION, TextType::CLOSED_CAPTION); + c->set_dcp_track (examiner->dcp_text_track(i)); + new_text.push_back (c); } { diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc index ca851db2d..a0bc487d9 100644 --- a/src/lib/dcp_examiner.cc +++ b/src/lib/dcp_examiner.cc @@ -53,7 +53,10 @@ using std::cout; using std::runtime_error; using std::map; using std::shared_ptr; +using std::string; using std::dynamic_pointer_cast; +using boost::optional; + DCPExaminer::DCPExaminer (shared_ptr content, bool tolerant) : DCP (content, tolerant) @@ -108,6 +111,15 @@ DCPExaminer::DCPExaminer (shared_ptr content, bool tolerant) _name = cpl->content_title_text (); _content_kind = cpl->content_kind (); + auto try_to_parse_language = [](optional lang) -> boost::optional { + try { + if (lang) { + return dcp::LanguageTag (*lang); + } + } catch (...) {} + return boost::none; + }; + for (auto i: cpl->reels()) { if (i->main_picture ()) { @@ -159,6 +171,7 @@ DCPExaminer::DCPExaminer (shared_ptr content, bool tolerant) } _audio_length += i->main_sound()->actual_duration(); + _audio_language = try_to_parse_language (asset->language()); } if (i->main_subtitle ()) { @@ -169,6 +182,7 @@ DCPExaminer::DCPExaminer (shared_ptr content, bool tolerant) } _text_count[static_cast(TextType::OPEN_SUBTITLE)] = 1; + _open_subtitle_language = try_to_parse_language (i->main_subtitle()->language()); } for (auto j: i->closed_captions()) { @@ -183,7 +197,7 @@ DCPExaminer::DCPExaminer (shared_ptr content, bool tolerant) } if (i->main_markers ()) { - map rm = i->main_markers()->get(); + auto rm = i->main_markers()->get(); _markers.insert (rm.begin(), rm.end()); } diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h index 3fedaca06..66f694f72 100644 --- a/src/lib/dcp_examiner.h +++ b/src/lib/dcp_examiner.h @@ -90,6 +90,10 @@ public: return _audio_frame_rate.get_value_or (48000); } + boost::optional audio_language () const { + return _audio_language; + } + /** @param type TEXT_OPEN_SUBTITLE or TEXT_CLOSED_CAPTION. * @return Number of assets of this type in this DCP. */ @@ -97,6 +101,10 @@ public: return _text_count[static_cast(type)]; } + boost::optional open_subtitle_language () const { + return _open_subtitle_language; + } + DCPTextTrack dcp_text_track (int i) const { DCPOMATIC_ASSERT (i >= 0 && i < static_cast(_dcp_text_tracks.size())); return _dcp_text_tracks[i]; @@ -162,8 +170,10 @@ private: bool _has_video = false; /** true if this DCP has audio content (but false if it has unresolved references to audio content) */ bool _has_audio = false; + boost::optional _audio_language; /** number of different assets of each type (OCAP/CCAP) */ int _text_count[static_cast(TextType::COUNT)]; + boost::optional _open_subtitle_language; /** the DCPTextTracks for each of our CCAPs */ std::vector _dcp_text_tracks; bool _encrypted = false; -- 2.30.2