Basic guessing of audio channels from filenames (#393).
authorCarl Hetherington <cth@carlh.net>
Tue, 14 Jun 2016 14:51:03 +0000 (15:51 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 14 Jun 2016 14:51:03 +0000 (15:51 +0100)
ChangeLog
src/lib/ffmpeg_content.cc
src/lib/film.cc
src/lib/film.h

index 99ec8dadffc0919a40ce797c33e88eb493368fa8..648f868142ff7bc681c09e71e737670fba2f429c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-06-14  c.hetherington  <cth@carlh.net>
 
+       * Basic guessing of audio channels from filenames (#393).
+
        * Fix incorrectly-reported frame rate when importing
        3D DCPs.
 
index b2b67e5656c13e1a3d928b43a5f92e1e19b939c7..b34fdf6aa811bd48fbfecf8a69b25c80ae51eafa 100644 (file)
@@ -218,6 +218,8 @@ FFmpegContent::examine (shared_ptr<Job> job)
                set_default_colour_conversion ();
        }
 
+       boost::filesystem::path first_path = path (0);
+
        {
                boost::mutex::scoped_lock lm (_mutex);
 
@@ -239,7 +241,7 @@ FFmpegContent::examine (shared_ptr<Job> job)
 
                        AudioStreamPtr as = audio->streams().front();
                        AudioMapping m = as->mapping ();
-                       film()->make_audio_mapping_default (m);
+                       film()->make_audio_mapping_default (m, first_path);
                        as->set_mapping (m);
                }
 
index ff5cba0001bd1a794e2d6099151ca6f2f62aa631..64550556b39bd3d27104468a1573f7ab8b7fd6a7 100644 (file)
@@ -62,6 +62,7 @@
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
+#include <boost/regex.hpp>
 #include <unistd.h>
 #include <stdexcept>
 #include <iostream>
@@ -1292,18 +1293,44 @@ Film::subtitle_language () const
 
 /** Change the gains of the supplied AudioMapping to make it a default
  *  for this film.  The defaults are guessed based on what processor (if any)
- *  is in use and the number of input channels.
+ *  is in use, the number of input channels and any filename supplied.
  */
 void
-Film::make_audio_mapping_default (AudioMapping& mapping) const
+Film::make_audio_mapping_default (AudioMapping& mapping, optional<boost::filesystem::path> filename) const
 {
+       static string const regex[] = {
+               ".*[\\._-]L[\\._-].*",
+               ".*[\\._-]R[\\._-].*",
+               ".*[\\._-]C[\\._-].*",
+               ".*[\\._-]Lfe[\\._-].*",
+               ".*[\\._-]Ls[\\._-].*",
+               ".*[\\._-]Rs[\\._-].*"
+       };
+
+       static int const regexes = sizeof(regex) / sizeof(*regex);
+
        if (audio_processor ()) {
                audio_processor()->make_audio_mapping_default (mapping);
        } else {
                mapping.make_zero ();
                if (mapping.input_channels() == 1) {
-                       /* Mono -> Centre */
-                       mapping.set (0, static_cast<int> (dcp::CENTRE), 1);
+                       bool guessed = false;
+
+                       /* See if we can guess where this stream should go */
+                       if (filename) {
+                               for (int i = 0; i < regexes; ++i) {
+                                       boost::regex e (regex[i], boost::regex::icase);
+                                       if (boost::regex_match (filename->string(), e) && i < mapping.output_channels()) {
+                                               mapping.set (0, i, 1);
+                                               guessed = true;
+                                       }
+                               }
+                       }
+
+                       if (!guessed) {
+                               /* If we have no idea, just put it on centre */
+                               mapping.set (0, static_cast<int> (dcp::CENTRE), 1);
+                       }
                } else {
                        /* 1:1 mapping */
                        for (int i = 0; i < min (mapping.input_channels(), mapping.output_channels()); ++i) {
index 3b33aa3058d3c37eb707a1f48b60db3190dd9cee..ca0855b5c2e58d5670394fcf2ca513c9f82a4350 100644 (file)
@@ -144,7 +144,11 @@ public:
 
        std::string subtitle_language () const;
 
-       void make_audio_mapping_default (AudioMapping & mapping) const;
+       void make_audio_mapping_default (
+               AudioMapping & mapping,
+               boost::optional<boost::filesystem::path> filename = boost::optional<boost::filesystem::path> ()
+               ) const;
+
        std::vector<std::string> audio_output_names () const;
 
        void repeat_content (ContentList, int);