Untested external audio support; AB transcodes still broken.
[dcpomatic.git] / src / lib / examine_content_job.cc
index 1e263ffa585f97b413bd4cbe84db6c77c65a7ad3..8db74801fdd634feed5e2a822c4d4f97691884b6 100644 (file)
 #include "transcoder.h"
 #include "log.h"
 #include "film.h"
+#include "video_decoder.h"
 
 using std::string;
 using std::vector;
+using std::pair;
 using boost::shared_ptr;
 
 ExamineContentJob::ExamineContentJob (shared_ptr<Film> f, shared_ptr<Job> req)
@@ -59,19 +61,29 @@ void
 ExamineContentJob::run ()
 {
        /* 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);
 
-       _decoder = decoder_factory (_film, o, this, true, true);
-       _decoder->go ();
+       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 (_decoder->last_video_frame ());
+       _film->set_length (decoders.first->video_frame());
 
-       _film->log()->log (String::compose ("Video length is %1 frames", _decoder->last_video_frame()));
+       _film->log()->log (String::compose ("Video length is %1 frames", _film->length()));
 
        ascend ();
 
@@ -84,7 +96,11 @@ ExamineContentJob::run ()
                o->out_size = _film->size ();
                o->apply_crop = false;
                o->decode_audio = false;
-               o->decode_video_frequency = 128;
+               if (_film->length() > 0) {
+                       o->decode_video_skip = _film->length().get() / 128;
+               } else {
+                       o->decode_video_skip = 0;
+               }
                o->decode_subtitles = true;
                shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (_film, o));
                Transcoder w (_film, o, this, e);
@@ -101,7 +117,7 @@ ExamineContentJob::run ()
        }
 
        string const tdir = _film->dir ("thumbs");
-       vector<int> thumbs;
+       vector<SourceFrame> thumbs;
 
        for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (tdir); i != boost::filesystem::directory_iterator(); ++i) {
 
@@ -126,9 +142,3 @@ ExamineContentJob::run ()
        set_progress (1);
        set_state (FINISHED_OK);
 }
-
-int
-ExamineContentJob::last_video_frame () const
-{
-       return _decoder->last_video_frame ();
-}