Merge branch 'master' into speed-up
authorCarl Hetherington <cth@carlh.net>
Sat, 15 Dec 2012 01:01:12 +0000 (01:01 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 15 Dec 2012 01:01:12 +0000 (01:01 +0000)
12 files changed:
ChangeLog
src/lib/examine_content_job.cc
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/film.cc
src/lib/film.h
src/lib/imagemagick_decoder.h
src/lib/transcoder.cc
src/lib/transcoder.h
src/lib/video_decoder.h
src/wx/film_editor.cc
src/wx/film_editor.h

index 6524aa3ed51afa6f731b72df8bc6dd0f91534fa1..e463d17c8dd53f27e9bdcfa3ab2c9aebf57f357b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
        * Fix specification of architecture in .debs.
 
+2012-12-10  Carl Hetherington  <cth@carlh.net>
+
+       * Add a check-box (which defaults to on) which tells DVD-o-matic
+       not to scan new content files to work out their length, but instead
+       to trust the length from the header.  This length only matters for
+       working out what thumbnails to generate, so it isn't critical.
+       Trusting the header will speed up the "Examine Content" job by
+       a factor of about 2, which is handy for large films.
+
 2012-12-10  Carl Hetherington  <cth@carlh.net>
 
        * Version 0.59 released.
index 8db74801fdd634feed5e2a822c4d4f97691884b6..93333605b8e6a6983fc63fd668f420bd426fae35 100644 (file)
@@ -60,51 +60,78 @@ ExamineContentJob::name () const
 void
 ExamineContentJob::run ()
 {
-       /* Decode the content to get an accurate length */
+       float progress_remaining = 1;
 
-       /* We don't want to use any existing length here, as progress
-          will be messed up.
+       /* Set the film's length to either
+          a) a length judged by running through the content or
+          b) the length from a decoder's header.
        */
-       _film->unset_length ();
-       
-       shared_ptr<Options> o (new Options ("", "", ""));
-       o->out_size = Size (512, 512);
-       o->apply_crop = false;
-       o->decode_audio = false;
-
-       descend (0.5);
 
-       pair<shared_ptr<VideoDecoder>, shared_ptr<AudioDecoder> > decoders = decoder_factory (_film, o, this);
+       if (!_film->trust_content_header()) {
+               /* Decode the content to get an accurate length */
+               
+               /* We don't want to use any existing length here, as progress
+                  will be messed up.
+               */
+               _film->unset_length ();
+               
+               shared_ptr<Options> o (new Options ("", "", ""));
+               o->out_size = Size (512, 512);
+               o->apply_crop = false;
+               o->decode_audio = false;
+               
+               descend (0.5);
+               
+               pair<shared_ptr<VideoDecoder>, shared_ptr<AudioDecoder> > decoders = decoder_factory (_film, o, this);
+               
+               set_progress_unknown ();
+               while (!decoders.first->pass()) {
+                       /* keep going */
+               }
+               
+               _film->set_length (decoders.first->video_frame());
+               
+               _film->log()->log (String::compose ("Video length examined as %1 frames", _film->length().get()));
+               
+               ascend ();
+               
+               progress_remaining -= 0.5;
+               
+       } else {
 
-       set_progress_unknown ();
-       while (!decoders.first->pass()) {
-               /* keep going */
+               /* Get a quick decoder to get the content's length from its header.
+                  It would have been nice to just use the thumbnail transcoder's decoder,
+                  but that's a bit fiddly, and this isn't too expensive.
+               */
+               
+               shared_ptr<Options> o (new Options ("", "", ""));
+               o->out_size = Size (1024, 1024);
+               pair<shared_ptr<VideoDecoder>, shared_ptr<AudioDecoder> > d = decoder_factory (_film, o, 0);
+               _film->set_length (d.first->length());
+       
+               _film->log()->log (String::compose ("Video length obtained from header as %1 frames", _film->length().get()));
        }
 
-       _film->set_length (decoders.first->video_frame());
-
-       _film->log()->log (String::compose ("Video length is %1 frames", _film->length()));
-
-       ascend ();
-
        /* Now make thumbnails for it */
 
-       descend (0.5);
+       descend (progress_remaining);
 
        try {
-               o.reset (new Options (_film->dir ("thumbs"), ".png", ""));
+               shared_ptr<Options> o (new Options (_film->dir ("thumbs"), ".png", ""));
                o->out_size = _film->size ();
                o->apply_crop = false;
                o->decode_audio = false;
-               if (_film->length() > 0) {
-                       o->decode_video_skip = _film->length().get() / 128;
-               } else {
-                       o->decode_video_skip = 0;
-               }
+               o->decode_video_skip = _film->length().get() / 128;
                o->decode_subtitles = true;
                shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (_film, o));
                Transcoder w (_film, o, this, e);
                w.go ();
+
+               /* Now set the film's length from the transcoder's decoder, since we
+                  went to all the trouble of going through the content.
+               */
+
+               _film->set_length (w.video_decoder()->video_frame());
                
        } catch (std::exception& e) {
 
index 46e851e372439a232169b77f1e0a229559dc831a..acaf149f43ade599dff78d95c109d36c86133097 100644 (file)
@@ -164,14 +164,7 @@ FFmpegDecoder::setup_video ()
                throw DecodeError ("could not find video decoder");
        }
 
-       /* I think this prevents problems with green hash on decodes and
-          "changing frame properties on the fly is not supported by all filters"
-          messages with some content.  Although I'm not sure; needs checking.
-       */
-       AVDictionary* opts = 0;
-       av_dict_set (&opts, "threads", "1", 0);
-       
-       if (avcodec_open2 (_video_codec_context, _video_codec, &opts) < 0) {
+       if (avcodec_open2 (_video_codec_context, _video_codec, 0) < 0) {
                throw DecodeError ("could not open video decoder");
        }
 }
@@ -638,3 +631,9 @@ FFmpegAudioStream::to_string () const
        return String::compose ("ffmpeg %1 %2 %3 %4", _id, _sample_rate, _channel_layout, _name);
 }
 
+/** @return Length (in video frames) according to our content's header */
+SourceFrame
+FFmpegDecoder::length () const
+{
+       return (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second();
+}
index 87eebe1ecc4ba7b83f92fb23f096435caf5bdd2b..1771551fcf1080cb5bb7b38b5d0744d3992c3d65 100644 (file)
@@ -56,7 +56,7 @@ public:
                , _name (n)
                , _id (i)
        {}
-                 
+
        std::string to_string () const;
 
        std::string name () const {
@@ -89,6 +89,7 @@ public:
 
        float frames_per_second () const;
        Size native_size () const;
+       SourceFrame length () const;
        int time_base_numerator () const;
        int time_base_denominator () const;
        int sample_aspect_ratio_numerator () const;
index 3f92100802ade784a839bef4a790a939fa547a2b..e2a4cbeda60efda1089f2b8e840c6a64940f5702 100644 (file)
@@ -86,6 +86,7 @@ int const Film::state_version = 1;
 
 Film::Film (string d, bool must_exist)
        : _use_dci_name (true)
+       , _trust_content_header (true)
        , _dcp_content_type (0)
        , _format (0)
        , _scaler (Scaler::from_id ("bicubic"))
@@ -144,6 +145,7 @@ Film::Film (Film const & o)
        , _name              (o._name)
        , _use_dci_name      (o._use_dci_name)
        , _content           (o._content)
+       , _trust_content_header (o._trust_content_header)
        , _dcp_content_type  (o._dcp_content_type)
        , _format            (o._format)
        , _crop              (o._crop)
@@ -404,6 +406,7 @@ Film::write_metadata () const
        f << "name " << _name << "\n";
        f << "use_dci_name " << _use_dci_name << "\n";
        f << "content " << _content << "\n";
+       f << "trust_content_header " << (_trust_content_header ? "1" : "0") << "\n";
        if (_dcp_content_type) {
                f << "dcp_content_type " << _dcp_content_type->pretty_name () << "\n";
        }
@@ -513,6 +516,8 @@ Film::read_metadata ()
                        _use_dci_name = (v == "1");
                } else if (k == "content") {
                        _content = v;
+               } else if (k == "trust_content_header") {
+                       _trust_content_header = (v == "1");
                } else if (k == "dcp_content_type") {
                        _dcp_content_type = DCPContentType::from_pretty_name (v);
                } else if (k == "format") {
@@ -976,7 +981,7 @@ Film::set_content (string c)
                signal_changed (CONTENT);
                
                set_content_digest (md5_digest (content_path ()));
-               
+
                examine_content ();
 
        } catch (...) {
@@ -987,6 +992,22 @@ Film::set_content (string c)
 
        }
 }
+
+void
+Film::set_trust_content_header (bool t)
+{
+       {
+               boost::mutex::scoped_lock lm (_state_mutex);
+               _trust_content_header = t;
+       }
+       
+       signal_changed (TRUST_CONTENT_HEADER);
+
+       if (!_trust_content_header) && !content().empty()) {
+               /* We just said that we don't trust the content's header */
+               examine_content ();
+       }
+}
               
 void
 Film::set_dcp_content_type (DCPContentType const * t)
index 2e81575e4710ef3fce0cee5ce9440eb1b4805387..8cd55a227994dd011040d64f3df19cb3ffca0ea3 100644 (file)
@@ -110,6 +110,7 @@ public:
                NAME,
                USE_DCI_NAME,
                CONTENT,
+               TRUST_CONTENT_HEADER,
                DCP_CONTENT_TYPE,
                FORMAT,
                CROP,
@@ -160,6 +161,11 @@ public:
                return _content;
        }
 
+       bool trust_content_header () const {
+               boost::mutex::scoped_lock lm (_state_mutex);
+               return _trust_content_header;
+       }
+
        DCPContentType const * dcp_content_type () const {
                boost::mutex::scoped_lock lm (_state_mutex);
                return _dcp_content_type;
@@ -329,6 +335,7 @@ public:
        void set_name (std::string);
        void set_use_dci_name (bool);
        void set_content (std::string);
+       void set_trust_content_header (bool);
        void set_dcp_content_type (DCPContentType const *);
        void set_format (Format const *);
        void set_crop (Crop);
@@ -404,6 +411,7 @@ private:
         *  or an absolute path.
         */
        std::string _content;
+       bool _trust_content_header;
        /** The type of content that this Film represents (feature, trailer etc.) */
        DCPContentType const * _dcp_content_type;
        /** The format to present this Film in (flat, scope, etc.) */
index f636191f2e3bdbb6da13d799c13a496cabbd6885..de49c1b566b6ef0a36ae2bb44c0e05d77a65da6c 100644 (file)
@@ -35,6 +35,11 @@ public:
 
        Size native_size () const;
 
+       SourceFrame length () const {
+               /* We don't know */
+               return 0;
+       }
+
        int audio_channels () const {
                return 0;
        }
index 537b9b66452d6f4b8e30dbe4f824b9983166fb0b..a7e79b05f74d6338cd2c5debfe6d77381b905839 100644 (file)
@@ -64,7 +64,9 @@ Transcoder::Transcoder (shared_ptr<Film> f, shared_ptr<const Options> o, Job* j,
 
        /* Set up the decoder to use the film's set streams */
        _decoders.first->set_subtitle_stream (f->subtitle_stream ());
-       _decoders.second->set_audio_stream (f->audio_stream ());
+       if (_decoders.second) {
+               _decoders.second->set_audio_stream (f->audio_stream ());
+       }
 
        if (_matcher) {
                _decoders.first->connect_video (_matcher);
@@ -73,7 +75,7 @@ Transcoder::Transcoder (shared_ptr<Film> f, shared_ptr<const Options> o, Job* j,
                _decoders.first->connect_video (_encoder);
        }
        
-       if (_matcher && _delay_line) {
+       if (_matcher && _delay_line && _decoders.second) {
                _decoders.second->connect_audio (_delay_line);
                _delay_line->connect_audio (_matcher);
                _matcher->connect_audio (_gain);
@@ -97,7 +99,7 @@ Transcoder::go ()
                                _decoders.first->set_progress ();
                        }
 
-                       if (!done[1] && dynamic_pointer_cast<Decoder> (_decoders.second) != dynamic_pointer_cast<Decoder> (_decoders.first)) {
+                       if (!done[1] && _decoders.second && dynamic_pointer_cast<Decoder> (_decoders.second) != dynamic_pointer_cast<Decoder> (_decoders.first)) {
                                done[1] = _decoders.second->pass ();
                        } else {
                                done[1] = true;
index e3ca2bb32085b128bb0c47673bcab7b55fed804a..4a9667b3c5165b95aa9f8aeea2786b206f184b56 100644 (file)
@@ -49,6 +49,10 @@ public:
 
        void go ();
 
+       boost::shared_ptr<VideoDecoder> video_decoder () const {
+               return _decoders.first;
+       }
+
 protected:
        /** A Job that is running this Transcoder, or 0 */
        Job* _job;
index ea1899840a7252a6358c682a0a1e85167bb3c7bd..685138a58c761d05307a71adb5b5dfdb74fc9889 100644 (file)
@@ -33,6 +33,8 @@ public:
        virtual float frames_per_second () const = 0;
        /** @return native size in pixels */
        virtual Size native_size () const = 0;
+       /** @return length (in source video frames), according to our content's header */
+       virtual SourceFrame length () const = 0;
 
        virtual int time_base_numerator () const = 0;
        virtual int time_base_denominator () const = 0;
index 2528f49db7b5fed47a08a303c8fd378821c04007..1e592e268d5093422688ab53fdd49c31cff3b479 100644 (file)
@@ -114,6 +114,11 @@ FilmEditor::make_film_panel ()
        _content = new wxFilePickerCtrl (_film_panel, wxID_ANY, wxT (""), wxT ("Select Content File"), wxT("*.*"));
        _film_sizer->Add (_content, 1, wxEXPAND);
 
+       _trust_content_header = new wxCheckBox (_film_panel, wxID_ANY, wxT ("Trust content's header"));
+       video_control (_trust_content_header);
+       _film_sizer->Add (_trust_content_header, 1);
+       _film_sizer->AddSpacer (0);
+
        add_label_to_sizer (_film_sizer, _film_panel, "Content Type");
        _dcp_content_type = new wxComboBox (_film_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, 0, 0, wxCB_READONLY);
        _film_sizer->Add (_dcp_content_type);
@@ -174,6 +179,7 @@ FilmEditor::connect_to_widgets ()
        _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
        _format->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
        _content->Connect (wxID_ANY, wxEVT_COMMAND_FILEPICKER_CHANGED, wxCommandEventHandler (FilmEditor::content_changed), 0, this);
+       _trust_content_header->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::trust_content_header_changed), 0, this);
        _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
        _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
        _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
@@ -427,6 +433,16 @@ FilmEditor::content_changed (wxCommandEvent &)
        }
 }
 
+void
+FilmEditor::trust_content_header_changed (wxCommandEvent &)
+{
+       if (!_film) {
+               return;
+       }
+
+       _film->set_trust_content_header (_trust_content_header->GetValue ());
+}
+
 /** Called when the DCP A/B switch has been toggled */
 void
 FilmEditor::dcp_ab_toggled (wxCommandEvent &)
@@ -495,6 +511,9 @@ FilmEditor::film_changed (Film::Property p)
                setup_subtitle_control_sensitivity ();
                setup_streams ();
                break;
+       case Film::TRUST_CONTENT_HEADER:
+               checked_set (_trust_content_header, _film->trust_content_header ());
+               break;
        case Film::SUBTITLE_STREAMS:
                setup_subtitle_control_sensitivity ();
                setup_streams ();
@@ -694,6 +713,7 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::NAME);
        film_changed (Film::USE_DCI_NAME);
        film_changed (Film::CONTENT);
+       film_changed (Film::TRUST_CONTENT_HEADER);
        film_changed (Film::DCP_CONTENT_TYPE);
        film_changed (Film::FORMAT);
        film_changed (Film::CROP);
@@ -731,6 +751,7 @@ FilmEditor::set_things_sensitive (bool s)
        _edit_dci_button->Enable (s);
        _format->Enable (s);
        _content->Enable (s);
+       _trust_content_header->Enable (s);
        _left_crop->Enable (s);
        _right_crop->Enable (s);
        _top_crop->Enable (s);
index 428b994b8e6c9beffa6eedcb98fb409705f64de2..7e75b4bf00841fbcd766778471a989f7f81ec425 100644 (file)
@@ -61,6 +61,7 @@ private:
        void top_crop_changed (wxCommandEvent &);
        void bottom_crop_changed (wxCommandEvent &);
        void content_changed (wxCommandEvent &);
+       void trust_content_header_changed (wxCommandEvent &);
        void format_changed (wxCommandEvent &);
        void dcp_trim_start_changed (wxCommandEvent &);
        void dcp_trim_end_changed (wxCommandEvent &);
@@ -118,6 +119,7 @@ private:
        wxComboBox* _format;
        /** The Film's content file */
        wxFilePickerCtrl* _content;
+       wxCheckBox* _trust_content_header;
        /** The Film's left crop */
        wxSpinCtrl* _left_crop;
        /** The Film's right crop */