Re-work again so that there's just one encoder; various tweaks to still-image-with...
authorCarl Hetherington <cth@carlh.net>
Wed, 19 Dec 2012 23:50:17 +0000 (23:50 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 19 Dec 2012 23:50:17 +0000 (23:50 +0000)
34 files changed:
src/lib/ab_transcode_job.cc
src/lib/ab_transcoder.cc
src/lib/combiner.cc
src/lib/combiner.h
src/lib/encoder.cc
src/lib/encoder.h
src/lib/encoder_factory.cc [deleted file]
src/lib/encoder_factory.h [deleted file]
src/lib/exceptions.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/film.cc
src/lib/film.h
src/lib/imagemagick_decoder.cc
src/lib/j2k_still_encoder.cc [deleted file]
src/lib/j2k_still_encoder.h [deleted file]
src/lib/j2k_video_encoder.cc [deleted file]
src/lib/j2k_video_encoder.h [deleted file]
src/lib/matcher.cc
src/lib/matcher.h
src/lib/options.h
src/lib/transcode_job.cc
src/lib/video_decoder.cc
src/lib/video_decoder.h
src/lib/video_sink.h
src/lib/video_source.cc
src/lib/video_source.h
src/lib/wscript
src/tools/dvdomatic.cc
src/tools/servomatictest.cc
src/wx/film_editor.cc
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/wx_util.cc

index da9ce7933cfe39cd9f3dc46b860a20fc95fbcb09..a6233c185783d42055be316361ff4e4713c76a3a 100644 (file)
@@ -23,8 +23,8 @@
 #include "format.h"
 #include "filter.h"
 #include "ab_transcoder.h"
-#include "encoder_factory.h"
 #include "config.h"
+#include "encoder.h"
 
 using std::string;
 using boost::shared_ptr;
@@ -53,7 +53,7 @@ ABTranscodeJob::run ()
 {
        try {
                /* _film_b is the one with reference filters */
-               ABTranscoder w (_film_b, _film, _decode_opt, this, encoder_factory (_film, _encode_opt));
+               ABTranscoder w (_film_b, _film, _decode_opt, this, shared_ptr<Encoder> (new Encoder (_film, _encode_opt)));
                w.go ();
                set_progress (1);
                set_state (FINISHED_OK);
index d85f078a5aa0e1601f01a90b8582fcdb1a95815f..53af43b5d91a2be5f259bad4d1d725fb3f18c067 100644 (file)
@@ -70,8 +70,8 @@ ABTranscoder::ABTranscoder (
        _db.video->set_subtitle_stream (_film_a->subtitle_stream ());
        _da.audio->set_audio_stream (_film_a->audio_stream ());
 
-       _da.video->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2));
-       _db.video->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2));
+       _da.video->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3));
+       _db.video->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3));
 
        if (_matcher) {
                _combiner->connect_video (_matcher);
index b85dbf288fba6a2bdc741744e470060e0c585d3c..d5f55026b54f8c14c597820fb6d1c454cf7c43b0 100644 (file)
@@ -33,7 +33,7 @@ Combiner::Combiner (Log* log)
  *  @param sub Subtitle (which will be ignored)
  */
 void
-Combiner::process_video (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
+Combiner::process_video (shared_ptr<Image> image, bool, shared_ptr<Subtitle> sub)
 {
        _image = image;
 }
@@ -43,7 +43,7 @@ Combiner::process_video (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
  *  @param sub Subtitle (which will be put onto the whole frame)
  */
 void
-Combiner::process_video_b (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
+Combiner::process_video_b (shared_ptr<Image> image, bool, shared_ptr<Subtitle> sub)
 {
        /* Copy the right half of this image into our _image */
        /* XXX: this should probably be in the Image class */
@@ -62,6 +62,6 @@ Combiner::process_video_b (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
                }
        }
 
-       Video (_image, sub);
+       Video (_image, false, sub);
        _image.reset ();
 }
index 78c9889b5bfcd4cb30e3229d7561811a171ded09..7fad1aeae84d44a486bb1d2b09b680274669e5c0 100644 (file)
@@ -33,8 +33,8 @@ class Combiner : public VideoProcessor
 public:
        Combiner (Log* log);
 
-       void process_video (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s);
-       void process_video_b (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s);
+       void process_video (boost::shared_ptr<Image> i, bool, boost::shared_ptr<Subtitle> s);
+       void process_video_b (boost::shared_ptr<Image> i, bool, boost::shared_ptr<Subtitle> s);
 
 private:
        /** The image that we are currently working on */
index f352f5a5246d4c48aa95fa6ba2b7233e4a46b449..7a475a8594c00eede242fd58c875c85b6a0baf60 100644 (file)
  */
 
 #include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
 #include "encoder.h"
 #include "util.h"
 #include "options.h"
 #include "film.h"
 #include "log.h"
 #include "exceptions.h"
+#include "filter.h"
+#include "config.h"
+#include "dcp_video_frame.h"
+#include "server.h"
+#include "cross.h"
 
 using std::pair;
+using std::string;
 using std::stringstream;
 using std::vector;
+using std::list;
+using std::cout;
 using namespace boost;
 
 int const Encoder::_history_size = 25;
@@ -49,6 +58,7 @@ Encoder::Encoder (shared_ptr<const Film> f, shared_ptr<const EncodeOptions> o)
        , _swr_context (0)
 #endif   
        , _audio_frames_written (0)
+       , _process_end (false)
 {
        if (_film->audio_stream()) {
                /* Create sound output files with .tmp suffixes; we will rename
@@ -72,6 +82,7 @@ Encoder::Encoder (shared_ptr<const Film> f, shared_ptr<const EncodeOptions> o)
 Encoder::~Encoder ()
 {
        close_sound_files ();
+       terminate_worker_threads ();
 }
 
 void
@@ -105,6 +116,18 @@ Encoder::process_begin ()
                _swr_context = 0;
 #endif         
        }
+
+       for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
+               _worker_threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, (ServerDescription *) 0)));
+       }
+
+       vector<ServerDescription*> servers = Config::instance()->servers ();
+
+       for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
+               for (int j = 0; j < (*i)->threads (); ++j) {
+                       _worker_threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, *i)));
+               }
+       }
 }
 
 
@@ -146,6 +169,43 @@ Encoder::process_end ()
                        boost::filesystem::rename (_opt->multichannel_audio_out_path (i, true), _opt->multichannel_audio_out_path (i, false));
                }
        }
+
+       boost::mutex::scoped_lock lock (_worker_mutex);
+
+       _film->log()->log ("Clearing queue of " + lexical_cast<string> (_queue.size ()));
+
+       /* Keep waking workers until the queue is empty */
+       while (!_queue.empty ()) {
+               _film->log()->log ("Waking with " + lexical_cast<string> (_queue.size ()), Log::VERBOSE);
+               _worker_condition.notify_all ();
+               _worker_condition.wait (lock);
+       }
+
+       lock.unlock ();
+       
+       terminate_worker_threads ();
+
+       _film->log()->log ("Mopping up " + lexical_cast<string> (_queue.size()));
+
+       /* The following sequence of events can occur in the above code:
+            1. a remote worker takes the last image off the queue
+            2. the loop above terminates
+            3. the remote worker fails to encode the image and puts it back on the queue
+            4. the remote worker is then terminated by terminate_worker_threads
+
+            So just mop up anything left in the queue here.
+       */
+
+       for (list<shared_ptr<DCPVideoFrame> >::iterator i = _queue.begin(); i != _queue.end(); ++i) {
+               _film->log()->log (String::compose ("Encode left-over frame %1", (*i)->frame ()));
+               try {
+                       shared_ptr<EncodedData> e = (*i)->encode_locally ();
+                       e->write (_opt, (*i)->frame ());
+                       frame_done ();
+               } catch (std::exception& e) {
+                       _film->log()->log (String::compose ("Local encode failed (%1)", e.what ()));
+               }
+       }
 }      
 
 /** @return an estimate of the current number of frames we are encoding per second,
@@ -209,7 +269,7 @@ Encoder::frame_skipped ()
 }
 
 void
-Encoder::process_video (shared_ptr<Image> i, boost::shared_ptr<Subtitle> s)
+Encoder::process_video (shared_ptr<Image> image, bool same, boost::shared_ptr<Subtitle> sub)
 {
        if (_opt->video_skip != 0 && (_video_frame % _opt->video_skip) != 0) {
                ++_video_frame;
@@ -224,7 +284,47 @@ Encoder::process_video (shared_ptr<Image> i, boost::shared_ptr<Subtitle> s)
                }
        }
 
-       do_process_video (i, s);
+       boost::mutex::scoped_lock lock (_worker_mutex);
+
+       /* Wait until the queue has gone down a bit */
+       while (_queue.size() >= _worker_threads.size() * 2 && !_process_end) {
+               TIMING ("decoder sleeps with queue of %1", _queue.size());
+               _worker_condition.wait (lock);
+               TIMING ("decoder wakes with queue of %1", _queue.size());
+       }
+
+       if (_process_end) {
+               return;
+       }
+
+       /* Only do the processing if we don't already have a file for this frame */
+       if (boost::filesystem::exists (_opt->frame_out_path (_video_frame, false))) {
+               frame_skipped ();
+               return;
+       }
+
+       if (same) {
+               /* Use the last frame that we encoded */
+               assert (_last_real_frame);
+               link (_opt->frame_out_path (_last_real_frame.get(), false), _opt->frame_out_path (_video_frame, false));
+               link (_opt->hash_out_path (_last_real_frame.get(), false), _opt->hash_out_path (_video_frame, false));
+       } else {
+               /* Queue this new frame for encoding */
+               pair<string, string> const s = Filter::ffmpeg_strings (_film->filters());
+               TIMING ("adding to queue of %1", _queue.size ());
+               _queue.push_back (boost::shared_ptr<DCPVideoFrame> (
+                                         new DCPVideoFrame (
+                                                 image, sub, _opt->out_size, _opt->padding, _film->subtitle_offset(), _film->subtitle_scale(),
+                                                 _film->scaler(), _video_frame, _film->frames_per_second(), s.second,
+                                                 Config::instance()->colour_lut_index (), Config::instance()->j2k_bandwidth (),
+                                                 _film->log()
+                                                 )
+                                         ));
+               
+               _worker_condition.notify_all ();
+               _last_real_frame = _video_frame;
+       }
+
        ++_video_frame;
 }
 
@@ -232,7 +332,6 @@ void
 Encoder::process_audio (shared_ptr<AudioBuffers> data)
 {
        if (_opt->audio_range) {
-
                shared_ptr<AudioBuffers> trimmed (new AudioBuffers (*data.get ()));
                
                /* Range that we are encoding */
@@ -306,3 +405,115 @@ Encoder::close_sound_files ()
        _sound_files.clear ();
 }      
 
+void
+Encoder::terminate_worker_threads ()
+{
+       boost::mutex::scoped_lock lock (_worker_mutex);
+       _process_end = true;
+       _worker_condition.notify_all ();
+       lock.unlock ();
+
+       for (list<boost::thread *>::iterator i = _worker_threads.begin(); i != _worker_threads.end(); ++i) {
+               (*i)->join ();
+               delete *i;
+       }
+}
+
+void
+Encoder::encoder_thread (ServerDescription* server)
+{
+       /* Number of seconds that we currently wait between attempts
+          to connect to the server; not relevant for localhost
+          encodings.
+       */
+       int remote_backoff = 0;
+       
+       while (1) {
+
+               TIMING ("encoder thread %1 sleeps", boost::this_thread::get_id());
+               boost::mutex::scoped_lock lock (_worker_mutex);
+               while (_queue.empty () && !_process_end) {
+                       _worker_condition.wait (lock);
+               }
+
+               if (_process_end) {
+                       return;
+               }
+
+               TIMING ("encoder thread %1 wakes with queue of %2", boost::this_thread::get_id(), _queue.size());
+               boost::shared_ptr<DCPVideoFrame> vf = _queue.front ();
+               _film->log()->log (String::compose ("Encoder thread %1 pops frame %2 from queue", boost::this_thread::get_id(), vf->frame()), Log::VERBOSE);
+               _queue.pop_front ();
+               
+               lock.unlock ();
+
+               shared_ptr<EncodedData> encoded;
+
+               if (server) {
+                       try {
+                               encoded = vf->encode_remotely (server);
+
+                               if (remote_backoff > 0) {
+                                       _film->log()->log (String::compose ("%1 was lost, but now she is found; removing backoff", server->host_name ()));
+                               }
+                               
+                               /* This job succeeded, so remove any backoff */
+                               remote_backoff = 0;
+                               
+                       } catch (std::exception& e) {
+                               if (remote_backoff < 60) {
+                                       /* back off more */
+                                       remote_backoff += 10;
+                               }
+                               _film->log()->log (
+                                       String::compose (
+                                               "Remote encode of %1 on %2 failed (%3); thread sleeping for %4s",
+                                               vf->frame(), server->host_name(), e.what(), remote_backoff)
+                                       );
+                       }
+                               
+               } else {
+                       try {
+                               TIMING ("encoder thread %1 begins local encode of %2", boost::this_thread::get_id(), vf->frame());
+                               encoded = vf->encode_locally ();
+                               TIMING ("encoder thread %1 finishes local encode of %2", boost::this_thread::get_id(), vf->frame());
+                       } catch (std::exception& e) {
+                               _film->log()->log (String::compose ("Local encode failed (%1)", e.what ()));
+                       }
+               }
+
+               if (encoded) {
+                       encoded->write (_opt, vf->frame ());
+                       frame_done ();
+               } else {
+                       lock.lock ();
+                       _film->log()->log (
+                               String::compose ("Encoder thread %1 pushes frame %2 back onto queue after failure", boost::this_thread::get_id(), vf->frame())
+                               );
+                       _queue.push_front (vf);
+                       lock.unlock ();
+               }
+
+               if (remote_backoff > 0) {
+                       dvdomatic_sleep (remote_backoff);
+               }
+
+               lock.lock ();
+               _worker_condition.notify_all ();
+       }
+}
+
+void
+Encoder::link (string a, string b) const
+{
+#ifdef DVDOMATIC_POSIX                 
+       int const r = symlink (a.c_str(), b.c_str());
+       if (r) {
+               throw EncodeError (String::compose ("could not create symlink from %1 to %2", a, b));
+       }
+#endif
+       
+#ifdef DVDOMATIC_WINDOWS
+       boost::filesystem::copy_file (a, b);
+#endif                 
+}
index f355daff7c39188131224207be03f55faeb9adc9..8ab4479efa18d6bf690b04546cc30b87e188afa6 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <boost/shared_ptr.hpp>
 #include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread.hpp>
 #include <list>
 #include <stdint.h>
 extern "C" {
@@ -46,15 +48,14 @@ class Image;
 class Subtitle;
 class AudioBuffers;
 class Film;
+class ServerDescription;
+class DCPVideoFrame;
 
 /** @class Encoder
- *  @brief Parent class for classes which can encode video and audio frames.
+ *  @brief Encoder to J2K and WAV for DCP.
  *
  *  Video is supplied to process_video as YUV frames, and audio
  *  is supplied as uncompressed PCM in blocks of various sizes.
- *
- *  The subclass is expected to encode the video and/or audio in
- *  some way and write it to disk.
  */
 
 class Encoder : public VideoSink, public AudioSink
@@ -68,9 +69,10 @@ public:
 
        /** Call with a frame of video.
         *  @param i Video frame image.
+        *  @param same true if i is the same as the last time we were called.
         *  @param s A subtitle that should be on this frame, or 0.
         */
-       void process_video (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s);
+       void process_video (boost::shared_ptr<Image> i, bool same, boost::shared_ptr<Subtitle> s);
 
        /** Call with some audio data */
        void process_audio (boost::shared_ptr<AudioBuffers>);
@@ -83,12 +85,6 @@ public:
        SourceFrame video_frame () const;
 
 protected:
-
-       /** Called with a frame of video.
-        *  @param i Video frame image.
-        *  @param s A subtitle that should be on this frame, or 0.
-        */
-       virtual void do_process_video (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s) = 0;
        
        void frame_done ();
        void frame_skipped ();
@@ -118,12 +114,23 @@ private:
        void close_sound_files ();
        void write_audio (boost::shared_ptr<const AudioBuffers> audio);
 
+       void encoder_thread (ServerDescription *);
+       void terminate_worker_threads ();
+       void link (std::string, std::string) const;
+
 #if HAVE_SWRESAMPLE    
        SwrContext* _swr_context;
 #endif 
 
        std::vector<SNDFILE*> _sound_files;
        int64_t _audio_frames_written;
+
+       boost::optional<int> _last_real_frame;
+       bool _process_end;
+       std::list<boost::shared_ptr<DCPVideoFrame> > _queue;
+       std::list<boost::thread *> _worker_threads;
+       mutable boost::mutex _worker_mutex;
+       boost::condition _worker_condition;
 };
 
 #endif
diff --git a/src/lib/encoder_factory.cc b/src/lib/encoder_factory.cc
deleted file mode 100644 (file)
index 8384ece..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file  src/encoder_factory.cc
- *  @brief A method to create an appropriate encoder for some content.
- */
-
-#include <boost/filesystem.hpp>
-#include "j2k_video_encoder.h"
-#include "j2k_still_encoder.h"
-#include "film.h"
-
-using boost::shared_ptr;
-
-shared_ptr<Encoder>
-encoder_factory (shared_ptr<const Film> f, shared_ptr<const EncodeOptions> o)
-{
-       if (!boost::filesystem::is_directory (f->content_path()) && f->content_type() == STILL) {
-               return shared_ptr<Encoder> (new J2KStillEncoder (f, o));
-       }
-       
-       return shared_ptr<Encoder> (new J2KVideoEncoder (f, o));
-}
diff --git a/src/lib/encoder_factory.h b/src/lib/encoder_factory.h
deleted file mode 100644 (file)
index 5ac5c95..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file  src/encoder_factory.h
- *  @brief A method to create an appropriate encoder for some content.
- */
-
-class Encoder;
-class EncodeOptions;
-class Job;
-class Log;
-class Film;
-
-extern boost::shared_ptr<Encoder> encoder_factory (boost::shared_ptr<const Film>, boost::shared_ptr<const EncodeOptions>);
index 8ef09875ba89383af42fe35ad2cdd99b08fa574a..bf8e85f0bdfb7d939f76b90ad41c4571361bd874 100644 (file)
@@ -224,19 +224,3 @@ public:
                : StringError (s)
        {}
 };
-
-class PlayError : public StringError
-{
-public:
-       PlayError (std::string s)
-               : StringError (s)
-       {}
-};
-
-class DVDError : public StringError
-{
-public:
-       DVDError (std::string s)
-               : StringError (s)
-       {}
-};
index 60bb3271e19e902fc125712fa1f3b5c1cafc5782..a19f26ad79bdfde7dc66e3d795d87254e5796d43 100644 (file)
@@ -572,10 +572,8 @@ FFmpegDecoder::filter_and_emit_video (AVFrame* frame)
 
        list<shared_ptr<Image> > images = graph->process (frame);
 
-       double const st = av_frame_get_best_effort_timestamp(_frame) * av_q2d (_format_context->streams[_video_stream]->time_base);
-
        for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
-               emit_video (*i, st);
+               emit_video (*i, frame_time ());
        }
 }
 
@@ -694,7 +692,7 @@ FFmpegDecoder::out_with_sync ()
                                String::compose (
                                        "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)",
                                        out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second()
-                                                       )
+                                       )
                                );
                }
        }
@@ -733,3 +731,9 @@ FFmpegDecoder::length () const
        return (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second();
 }
 
+double
+FFmpegDecoder::frame_time () const
+{
+       return av_frame_get_best_effort_timestamp(_frame) * av_q2d (_format_context->streams[_video_stream]->time_base);
+}
+
index 89534a38c6cd935c3be374178b2023121e97ffae..2fb8675f996b243e13b097b5feba65ef8d1c9727 100644 (file)
@@ -113,6 +113,7 @@ private:
 
        void out_with_sync ();
        void filter_and_emit_video (AVFrame *);
+       double frame_time () const;
 
        void setup_general ();
        void setup_video ();
index 9da15a73baf31ffc36f27bbfa05f87e61ad4310a..e7687fe3c14f90e09a8ccbbe0ba63d1e8eece7ad 100644 (file)
@@ -131,8 +131,10 @@ Film::Film (string d, bool must_exist)
        }
 
        _external_audio_stream = ExternalAudioStream::create ();
-
-       read_metadata ();
+       
+       if (must_exist) {
+               read_metadata ();
+       }
 
        _log = new FileLog (file ("log"));
        set_dci_date_today ();
@@ -267,8 +269,18 @@ Film::make_dcp (bool transcode)
                oe->video_range = make_pair (dcp_trim_start(), dcp_trim_start() + dcp_length().get());
                if (audio_stream()) {
                        oe->audio_range = make_pair (
-                               video_frames_to_audio_frames (oe->video_range.get().first, audio_stream()->sample_rate(), frames_per_second()),
-                               video_frames_to_audio_frames (oe->video_range.get().second, audio_stream()->sample_rate(), frames_per_second())
+
+                               video_frames_to_audio_frames (
+                                       oe->video_range.get().first,
+                                       dcp_audio_sample_rate (audio_stream()->sample_rate()),
+                                       dcp_frame_rate (frames_per_second()).frames_per_second
+                                       ),
+                               
+                               video_frames_to_audio_frames (
+                                       oe->video_range.get().second,
+                                       dcp_audio_sample_rate (audio_stream()->sample_rate()),
+                                       dcp_frame_rate (frames_per_second()).frames_per_second
+                                       )
                                );
                }
                        
@@ -449,8 +461,12 @@ Film::read_metadata ()
        boost::optional<int> audio_sample_rate;
        boost::optional<int> audio_stream_index;
        boost::optional<int> subtitle_stream_index;
-       
+
        ifstream f (file ("metadata").c_str());
+       if (!f.good()) {
+               throw OpenFileError (file("metadata"));
+       }
+       
        multimap<string, string> kv = read_key_value (f);
 
        /* We need version before anything else */
@@ -675,7 +691,7 @@ Film::target_audio_sample_rate () const
        return rint (t);
 }
 
-boost::optional<SourceFrame>
+boost::optional<int>
 Film::dcp_length () const
 {
        if (content_type() == STILL) {
@@ -683,7 +699,7 @@ Film::dcp_length () const
        }
        
        if (!length()) {
-               return boost::optional<SourceFrame> ();
+               return boost::optional<int> ();
        }
 
        return length().get() - dcp_trim_start() - dcp_trim_end();
@@ -850,6 +866,9 @@ Film::set_content (string c)
        _content_audio_stream = shared_ptr<AudioStream> ();
        _subtitle_stream = shared_ptr<SubtitleStream> ();
 
+       /* Start off using content audio */
+       set_use_content_audio (true);
+
        /* Create a temporary decoder so that we can get information
           about the content.
        */
index 536855b1f64a0abd4e80c6d7a0121b3fe787773e..b8a824233b79608b1fd116b7b9da7de14eb38c8a 100644 (file)
@@ -88,7 +88,7 @@ public:
        void read_metadata ();
 
        Size cropped_size (Size) const;
-       boost::optional<SourceFrame> dcp_length () const;
+       boost::optional<int> dcp_length () const;
        std::string dci_name () const;
        std::string dcp_name () const;
 
@@ -412,10 +412,10 @@ private:
        std::vector<Filter const *> _filters;
        /** Scaler algorithm to use */
        Scaler const * _scaler;
-       /** Frames to trim off the start of the source */
-       SourceFrame _dcp_trim_start;
-       /** Frames to trim off the end of the source */
-       SourceFrame _dcp_trim_end;
+       /** Frames to trim off the start of the DCP */
+       int _dcp_trim_start;
+       /** Frames to trim off the end of the DCP */
+       int _dcp_trim_end;
        /** true to create an A/B comparison DCP, where the left half of the image
            is the video without any filters or post-processing, and the right half
            has the specified filters and post-processing.
index 131eaa5007cd2443967e6c64c6b8ac74763be96a..bad1fb81314e182ccbc831d19462e33e5cc3fb51 100644 (file)
@@ -70,7 +70,12 @@ bool
 ImageMagickDecoder::pass ()
 {
        if (_iter == _files.end()) {
-               return true;
+               if (!_film->dcp_length() || video_frame() >= _film->dcp_length().get()) {
+                       return true;
+               }
+
+               repeat_last_video ();
+               return false;
        }
        
        Magick::Image* magick_image = new Magick::Image (_film->content_path ());
diff --git a/src/lib/j2k_still_encoder.cc b/src/lib/j2k_still_encoder.cc
deleted file mode 100644 (file)
index 9682576..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file  src/j2k_still_encoder.cc
- *  @brief An encoder which writes JPEG2000 files for a single still source image.
- */
-
-#include <sstream>
-#include <stdexcept>
-#include <iomanip>
-#include <iostream>
-#include <boost/filesystem.hpp>
-#include <sndfile.h>
-#include <openjpeg.h>
-#include "j2k_still_encoder.h"
-#include "config.h"
-#include "options.h"
-#include "exceptions.h"
-#include "dcp_video_frame.h"
-#include "filter.h"
-#include "log.h"
-#include "imagemagick_decoder.h"
-#include "film.h"
-
-using std::string;
-using std::pair;
-using boost::shared_ptr;
-
-J2KStillEncoder::J2KStillEncoder (shared_ptr<const Film> f, shared_ptr<const EncodeOptions> o)
-       : Encoder (f, o)
-{
-       
-}
-
-void
-J2KStillEncoder::do_process_video (shared_ptr<Image> yuv, shared_ptr<Subtitle> sub)
-{
-       pair<string, string> const s = Filter::ffmpeg_strings (_film->filters());
-       DCPVideoFrame* f = new DCPVideoFrame (
-               yuv, sub, _opt->out_size, _opt->padding, _film->subtitle_offset(), _film->subtitle_scale(), _film->scaler(), 0, _film->frames_per_second(), s.second,
-               Config::instance()->colour_lut_index(), Config::instance()->j2k_bandwidth(),
-               _film->log()
-               );
-
-       if (!boost::filesystem::exists (_opt->frame_out_path (0, false))) {
-               boost::shared_ptr<EncodedData> e = f->encode_locally ();
-               e->write (_opt, 0);
-       }
-
-       string const real = _opt->frame_out_path (0, false);
-       string const real_hash = _opt->hash_out_path (0, false);
-       for (int i = 1; i < (_film->still_duration() * _film->frames_per_second()); ++i) {
-
-               if (!boost::filesystem::exists (_opt->frame_out_path (i, false))) {
-                       link (real, _opt->frame_out_path (i, false));
-               }
-               
-               if (!boost::filesystem::exists (_opt->hash_out_path (i, false))) {
-                       link (real_hash, _opt->hash_out_path (i, false));
-               }
-               
-               frame_done ();
-       }
-}
-
-void
-J2KStillEncoder::link (string a, string b) const
-{
-#ifdef DVDOMATIC_POSIX                 
-       int const r = symlink (a.c_str(), b.c_str());
-       if (r) {
-               throw EncodeError ("could not create symlink");
-       }
-#endif
-       
-#ifdef DVDOMATIC_WINDOWS
-       boost::filesystem::copy_file (a, b);
-#endif                 
-}
diff --git a/src/lib/j2k_still_encoder.h b/src/lib/j2k_still_encoder.h
deleted file mode 100644 (file)
index ad2a5d2..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file  src/j2k_still_encoder.h
- *  @brief An encoder which writes JPEG2000 files for a single still source image.
- */
-
-#include <list>
-#include <vector>
-#include "encoder.h"
-
-class Image;
-class Log;
-class EncodeOptions;
-
-/** @class J2KStillEncoder
- *  @brief An encoder which writes repeated JPEG2000 files from a single decoded input.
- */
-class J2KStillEncoder : public Encoder
-{
-public:
-       J2KStillEncoder (boost::shared_ptr<const Film>, boost::shared_ptr<const EncodeOptions>);
-
-private:
-       void do_process_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
-
-       void link (std::string, std::string) const;
-};
diff --git a/src/lib/j2k_video_encoder.cc b/src/lib/j2k_video_encoder.cc
deleted file mode 100644 (file)
index 0f010b9..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file  src/j2k_video_encoder.cc
- *  @brief An encoder which writes JPEG2000 files, where they are video (ie not still).
- */
-
-#include <sstream>
-#include <stdexcept>
-#include <iomanip>
-#include <iostream>
-#include <boost/thread.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
-#include <sndfile.h>
-#include <openjpeg.h>
-#include "j2k_video_encoder.h"
-#include "config.h"
-#include "options.h"
-#include "exceptions.h"
-#include "dcp_video_frame.h"
-#include "server.h"
-#include "filter.h"
-#include "log.h"
-#include "cross.h"
-#include "film.h"
-
-using std::string;
-using std::stringstream;
-using std::list;
-using std::vector;
-using std::pair;
-using std::cout;
-using boost::shared_ptr;
-using boost::thread;
-using boost::lexical_cast;
-
-J2KVideoEncoder::J2KVideoEncoder (shared_ptr<const Film> f, shared_ptr<const EncodeOptions> o)
-       : Encoder (f, o)
-       , _process_end (false)
-{
-       
-}
-
-J2KVideoEncoder::~J2KVideoEncoder ()
-{
-       terminate_worker_threads ();
-}
-
-void
-J2KVideoEncoder::terminate_worker_threads ()
-{
-       boost::mutex::scoped_lock lock (_worker_mutex);
-       _process_end = true;
-       _worker_condition.notify_all ();
-       lock.unlock ();
-
-       for (list<boost::thread *>::iterator i = _worker_threads.begin(); i != _worker_threads.end(); ++i) {
-               (*i)->join ();
-               delete *i;
-       }
-}
-
-void
-J2KVideoEncoder::do_process_video (shared_ptr<Image> yuv, shared_ptr<Subtitle> sub)
-{
-       boost::mutex::scoped_lock lock (_worker_mutex);
-
-       /* Wait until the queue has gone down a bit */
-       while (_queue.size() >= _worker_threads.size() * 2 && !_process_end) {
-               TIMING ("decoder sleeps with queue of %1", _queue.size());
-               _worker_condition.wait (lock);
-               TIMING ("decoder wakes with queue of %1", _queue.size());
-       }
-
-       if (_process_end) {
-               return;
-       }
-
-       /* Only do the processing if we don't already have a file for this frame */
-       if (!boost::filesystem::exists (_opt->frame_out_path (_video_frame, false))) {
-               pair<string, string> const s = Filter::ffmpeg_strings (_film->filters());
-               TIMING ("adding to queue of %1", _queue.size ());
-               _queue.push_back (boost::shared_ptr<DCPVideoFrame> (
-                                         new DCPVideoFrame (
-                                                 yuv, sub, _opt->out_size, _opt->padding, _film->subtitle_offset(), _film->subtitle_scale(),
-                                                 _film->scaler(), _video_frame, _film->frames_per_second(), s.second,
-                                                 Config::instance()->colour_lut_index (), Config::instance()->j2k_bandwidth (),
-                                                 _film->log()
-                                                 )
-                                         ));
-               
-               _worker_condition.notify_all ();
-       } else {
-               frame_skipped ();
-       }
-}
-
-void
-J2KVideoEncoder::encoder_thread (ServerDescription* server)
-{
-       /* Number of seconds that we currently wait between attempts
-          to connect to the server; not relevant for localhost
-          encodings.
-       */
-       int remote_backoff = 0;
-       
-       while (1) {
-
-               TIMING ("encoder thread %1 sleeps", boost::this_thread::get_id());
-               boost::mutex::scoped_lock lock (_worker_mutex);
-               while (_queue.empty () && !_process_end) {
-                       _worker_condition.wait (lock);
-               }
-
-               if (_process_end) {
-                       return;
-               }
-
-               TIMING ("encoder thread %1 wakes with queue of %2", boost::this_thread::get_id(), _queue.size());
-               boost::shared_ptr<DCPVideoFrame> vf = _queue.front ();
-               _film->log()->log (String::compose ("Encoder thread %1 pops frame %2 from queue", boost::this_thread::get_id(), vf->frame()), Log::VERBOSE);
-               _queue.pop_front ();
-               
-               lock.unlock ();
-
-               shared_ptr<EncodedData> encoded;
-
-               if (server) {
-                       try {
-                               encoded = vf->encode_remotely (server);
-
-                               if (remote_backoff > 0) {
-                                       _film->log()->log (String::compose ("%1 was lost, but now she is found; removing backoff", server->host_name ()));
-                               }
-                               
-                               /* This job succeeded, so remove any backoff */
-                               remote_backoff = 0;
-                               
-                       } catch (std::exception& e) {
-                               if (remote_backoff < 60) {
-                                       /* back off more */
-                                       remote_backoff += 10;
-                               }
-                               _film->log()->log (
-                                       String::compose (
-                                               "Remote encode of %1 on %2 failed (%3); thread sleeping for %4s",
-                                               vf->frame(), server->host_name(), e.what(), remote_backoff)
-                                       );
-                       }
-                               
-               } else {
-                       try {
-                               TIMING ("encoder thread %1 begins local encode of %2", boost::this_thread::get_id(), vf->frame());
-                               encoded = vf->encode_locally ();
-                               TIMING ("encoder thread %1 finishes local encode of %2", boost::this_thread::get_id(), vf->frame());
-                       } catch (std::exception& e) {
-                               _film->log()->log (String::compose ("Local encode failed (%1)", e.what ()));
-                       }
-               }
-
-               if (encoded) {
-                       encoded->write (_opt, vf->frame ());
-                       frame_done ();
-               } else {
-                       lock.lock ();
-                       _film->log()->log (
-                               String::compose ("Encoder thread %1 pushes frame %2 back onto queue after failure", boost::this_thread::get_id(), vf->frame())
-                               );
-                       _queue.push_front (vf);
-                       lock.unlock ();
-               }
-
-               if (remote_backoff > 0) {
-                       dvdomatic_sleep (remote_backoff);
-               }
-
-               lock.lock ();
-               _worker_condition.notify_all ();
-       }
-}
-
-void
-J2KVideoEncoder::process_begin ()
-{
-       Encoder::process_begin ();
-       
-       for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
-               _worker_threads.push_back (new boost::thread (boost::bind (&J2KVideoEncoder::encoder_thread, this, (ServerDescription *) 0)));
-       }
-
-       vector<ServerDescription*> servers = Config::instance()->servers ();
-
-       for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
-               for (int j = 0; j < (*i)->threads (); ++j) {
-                       _worker_threads.push_back (new boost::thread (boost::bind (&J2KVideoEncoder::encoder_thread, this, *i)));
-               }
-       }
-}
-
-void
-J2KVideoEncoder::process_end ()
-{
-       Encoder::process_end ();
-       
-       boost::mutex::scoped_lock lock (_worker_mutex);
-
-       _film->log()->log ("Clearing queue of " + lexical_cast<string> (_queue.size ()));
-
-       /* Keep waking workers until the queue is empty */
-       while (!_queue.empty ()) {
-               _film->log()->log ("Waking with " + lexical_cast<string> (_queue.size ()), Log::VERBOSE);
-               _worker_condition.notify_all ();
-               _worker_condition.wait (lock);
-       }
-
-       lock.unlock ();
-       
-       terminate_worker_threads ();
-
-       _film->log()->log ("Mopping up " + lexical_cast<string> (_queue.size()));
-
-       /* The following sequence of events can occur in the above code:
-            1. a remote worker takes the last image off the queue
-            2. the loop above terminates
-            3. the remote worker fails to encode the image and puts it back on the queue
-            4. the remote worker is then terminated by terminate_worker_threads
-
-            So just mop up anything left in the queue here.
-       */
-
-       for (list<shared_ptr<DCPVideoFrame> >::iterator i = _queue.begin(); i != _queue.end(); ++i) {
-               _film->log()->log (String::compose ("Encode left-over frame %1", (*i)->frame ()));
-               try {
-                       shared_ptr<EncodedData> e = (*i)->encode_locally ();
-                       e->write (_opt, (*i)->frame ());
-                       frame_done ();
-               } catch (std::exception& e) {
-                       _film->log()->log (String::compose ("Local encode failed (%1)", e.what ()));
-               }
-       }
-}
-
diff --git a/src/lib/j2k_video_encoder.h b/src/lib/j2k_video_encoder.h
deleted file mode 100644 (file)
index 6041105..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file  src/j2k_video_encoder.h
- *  @brief An encoder which writes JPEG2000 files, where they are video (ie not still).
- */
-
-#include <list>
-#include <vector>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread.hpp>
-#include "encoder.h"
-
-class ServerDescription;
-class DCPVideoFrame;
-class Image;
-class Log;
-class Subtitle;
-
-/** @class J2KVideoEncoder
- *  @brief An encoder which writes JPEG2000 files, where they are video (ie not still).
- */
-class J2KVideoEncoder : public Encoder
-{
-public:
-       J2KVideoEncoder (boost::shared_ptr<const Film>, boost::shared_ptr<const EncodeOptions>);
-       ~J2KVideoEncoder ();
-
-       void process_begin ();
-       void process_end ();
-
-private:
-
-       void do_process_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
-       
-       void encoder_thread (ServerDescription *);
-       void terminate_worker_threads ();
-
-       bool _process_end;
-       std::list<boost::shared_ptr<DCPVideoFrame> > _queue;
-       std::list<boost::thread *> _worker_threads;
-       mutable boost::mutex _worker_mutex;
-       boost::condition _worker_condition;
-};
index 2dd36c11e79a1d60328eb5d0e828bf1266d5851b..2b7a080fc91aea71f522570205cd5053246d7cce 100644 (file)
@@ -35,9 +35,9 @@ Matcher::Matcher (Log* log, int sample_rate, float frames_per_second)
 }
 
 void
-Matcher::process_video (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s)
+Matcher::process_video (boost::shared_ptr<Image> i, bool same, boost::shared_ptr<Subtitle> s)
 {
-       Video (i, s);
+       Video (i, same, s);
        _video_frames++;
 
        _pixel_format = i->pixel_format ();
@@ -84,7 +84,7 @@ Matcher::process_end ()
                shared_ptr<Image> black (new SimpleImage (_pixel_format.get(), _size.get(), false));
                black->make_black ();
                for (int i = 0; i < black_video_frames; ++i) {
-                       Video (black, shared_ptr<Subtitle>());
+                       Video (black, i != 0, shared_ptr<Subtitle>());
                }
                
                /* Now recompute our check value */
index 03efd5cc0f8092f9496509569985272f60efcc2e..9bd30fe620bef802284a7ba06faf93cddc380589 100644 (file)
@@ -24,7 +24,7 @@ class Matcher : public AudioVideoProcessor
 {
 public:
        Matcher (Log* log, int sample_rate, float frames_per_second);
-       void process_video (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s);
+       void process_video (boost::shared_ptr<Image> i, bool, boost::shared_ptr<Subtitle> s);
        void process_audio (boost::shared_ptr<AudioBuffers>);
        void process_end ();
 
index 10cdfa8cdb659e31e1ebda9c9510dbda7e56c13c..55b066a2d90bb918d53b9a315b62d66fe8020a7b 100644 (file)
@@ -93,9 +93,9 @@ public:
        Size out_size;              ///< size of output images
        int padding;                ///< number of pixels of padding (in terms of the output size) each side of the image
 
-       /** Range of video frames to decode */
-       boost::optional<std::pair<SourceFrame, SourceFrame> > video_range;
-       /** Range of audio frames to decode */
+       /** Range of video frames to encode (in DCP frames) */
+       boost::optional<std::pair<int, int> > video_range;
+       /** Range of audio frames to decode (in the DCP's sampling rate) */
        boost::optional<std::pair<int64_t, int64_t> > audio_range;
        
        /** Skip frames such that we don't decode any frame where (index % decode_video_skip) != 0; e.g.
index b429c4646e67f751f285e3033d47cf71eef4b72f..dfb9b107192748f7dbe8c6b4f2280cd69fa05057 100644 (file)
@@ -28,7 +28,6 @@
 #include "format.h"
 #include "transcoder.h"
 #include "log.h"
-#include "encoder_factory.h"
 #include "encoder.h"
 
 using std::string;
@@ -63,7 +62,7 @@ TranscodeJob::run ()
                _film->log()->log ("Transcode job starting");
                _film->log()->log (String::compose ("Audio delay is %1ms", _film->audio_delay()));
 
-               _encoder = encoder_factory (_film, _encode_opt);
+               _encoder.reset (new Encoder (_film, _encode_opt));
                Transcoder w (_film, _decode_opt, this, _encoder);
                w.go ();
                set_progress (1);
index e723610b320056668afc5328d59eca49b5213c5d..e0a7576eeaf5c51670cf1702c6b7b4597467db15 100644 (file)
@@ -49,7 +49,7 @@ VideoDecoder::emit_video (shared_ptr<Image> image, double t)
                sub = _timed_subtitle->subtitle ();
        }
 
-       signal_video (image, sub);
+       signal_video (image, false, sub);
        _last_source_time = t;
 }
 
@@ -61,14 +61,14 @@ VideoDecoder::repeat_last_video ()
                _last_image->make_black ();
        }
 
-       signal_video (_last_image, _last_subtitle);
+       signal_video (_last_image, true, _last_subtitle);
 }
 
 void
-VideoDecoder::signal_video (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
+VideoDecoder::signal_video (shared_ptr<Image> image, bool same, shared_ptr<Subtitle> sub)
 {
        TIMING ("Decoder emits %1", _video_frame);
-       Video (image, sub);
+       Video (image, same, sub);
        ++_video_frame;
 
        _last_image = image;
index 97bbb0e48d0191f293fc621c2e0e57c7ae5c55da..7726d2057fe9b3eec7c5a20914d4b159ef4ce071 100644 (file)
@@ -75,7 +75,7 @@ protected:
        std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
 
 private:
-       void signal_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
+       void signal_video (boost::shared_ptr<Image>, bool, boost::shared_ptr<Subtitle>);
 
        int _video_frame;
        double _last_source_time;
index 78500c643a46cb4e8c181775bbb60a848b96e382..7c128cf73008d7ca8e71a5f4aa5c3aa52b3b4f8a 100644 (file)
@@ -31,9 +31,10 @@ class VideoSink
 public:
        /** Call with a frame of video.
         *  @param i Video frame image.
+        *  @param same true if i is the same as last time we were called.
         *  @param s A subtitle that should be on this frame, or 0.
         */
-       virtual void process_video (boost::shared_ptr<Image> i, boost::shared_ptr<Subtitle> s) = 0;
+       virtual void process_video (boost::shared_ptr<Image> i, bool same, boost::shared_ptr<Subtitle> s) = 0;
 };
 
 #endif
index c6bd4a5cf22d6ab3f0b1cf2458a70361b83a6227..56742e2b4729a988680ee50bf5536e8682fbba16 100644 (file)
@@ -26,5 +26,5 @@ using boost::bind;
 void
 VideoSource::connect_video (shared_ptr<VideoSink> s)
 {
-       Video.connect (bind (&VideoSink::process_video, s, _1, _2));
+       Video.connect (bind (&VideoSink::process_video, s, _1, _2, _3));
 }
index d53589e2e21448da56c83b6a437255a2a2563194..893629160eb4bc61a7327302e07923671bfd0b3e 100644 (file)
@@ -41,9 +41,10 @@ public:
 
        /** Emitted when a video frame is ready.
         *  First parameter is the video image.
-        *  Second parameter is either 0 or a subtitle that should be on this frame.
+        *  Second parameter is true if the image is the same as the last one that was emitted.
+        *  Third parameter is either 0 or a subtitle that should be on this frame.
         */
-       boost::signals2::signal<void (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>)> Video;
+       boost::signals2::signal<void (boost::shared_ptr<Image>, bool, boost::shared_ptr<Subtitle>)> Video;
 
        void connect_video (boost::shared_ptr<VideoSink>);
 };
index d13de4f3ba62fc3eccde160022543dff027cd109..b2b639f06d375928c9872e12b288136fa3f2da0f 100644 (file)
@@ -25,7 +25,6 @@ def build(bld):
                  delay_line.cc
                  dolby_cp750.cc
                 encoder.cc
-                 encoder_factory.cc
                 examine_content_job.cc
                 external_audio_decoder.cc
                  filter_graph.cc
@@ -37,8 +36,6 @@ def build(bld):
                  gain.cc
                  image.cc
                  imagemagick_decoder.cc
-                j2k_still_encoder.cc
-                j2k_video_encoder.cc
                 job.cc
                 job_manager.cc
                 log.cc
index d5d5bfc2f906ac21c0a7499c636df5041739a98d..59f3ebc3e05212557a333a730dfcf2f3a04aec3f 100644 (file)
@@ -288,9 +288,13 @@ public:
                
                if (r == wxID_OK) {
                        maybe_save_then_delete_film ();
-                       film.reset (new Film (wx_to_std (c->GetPath ())));
-                       film->log()->set_level (log_level);
-                       set_film ();
+                       try {
+                               film.reset (new Film (wx_to_std (c->GetPath ())));
+                               film->log()->set_level (log_level);
+                               set_film ();
+                       } catch (std::exception& e) {
+                               error_dialog (this, String::compose ("Could not open film at %1 (%2)", wx_to_std (c->GetPath()), e.what()));
+                       }
                }
 
                c->Destroy ();
index 41ec8075d174396f4dcee631ed390fcda281f178..88c2a833ece8e1972964ed294ec9b67b548a7cc7 100644 (file)
@@ -42,7 +42,7 @@ static Server* server;
 static Log log_ ("servomatictest.log");
 
 void
-process_video (shared_ptr<Image> image, int frame)
+process_video (shared_ptr<Image> image, bool, int frame)
 {
        shared_ptr<DCPVideoFrame> local (new DCPVideoFrame (image, Size (1024, 1024), 0, Scaler::from_id ("bicubic"), frame, 24, "", 0, 250000000, &log_));
        shared_ptr<DCPVideoFrame> remote (new DCPVideoFrame (image, Size (1024, 1024), 0, Scaler::from_id ("bicubic"), frame, 24, "", 0, 250000000, &log_));
index 999ea8753f68bd45b9141bfc9a2c536da3b38e23..c3f71917254e197828adcb76f29196d81b9d644a 100644 (file)
@@ -63,7 +63,7 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        , _film (f)
        , _generally_sensitive (true)
 {
-       wxSizer* s = new wxBoxSizer (wxVERTICAL);
+       wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
        SetSizer (s);
        _notebook = new wxNotebook (this, wxID_ANY);
        s->Add (_notebook, 1);
@@ -725,6 +725,7 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::USE_CONTENT_AUDIO);
        film_changed (Film::AUDIO_GAIN);
        film_changed (Film::AUDIO_DELAY);
+       film_changed (Film::STILL_DURATION);
        film_changed (Film::WITH_SUBTITLES);
        film_changed (Film::SUBTITLE_OFFSET);
        film_changed (Film::SUBTITLE_SCALE);
@@ -846,6 +847,15 @@ FilmEditor::setup_visibility ()
        }
 
        _film_sizer->Layout ();
+       _film_sizer->SetSizeHints (_film_panel);
+       _video_sizer->Layout ();
+       _video_sizer->SetSizeHints (_video_panel);
+       _audio_sizer->Layout ();
+       _audio_sizer->SetSizeHints (_audio_panel);
+       _subtitle_sizer->Layout ();
+       _subtitle_sizer->SetSizeHints (_subtitle_panel);
+
+       _notebook->Fit ();
 }
 
 void
@@ -1001,6 +1011,7 @@ FilmEditor::setup_streams ()
        vector<shared_ptr<AudioStream> > a = _film->content_audio_streams ();
        for (vector<shared_ptr<AudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
                shared_ptr<FFmpegAudioStream> ffa = dynamic_pointer_cast<FFmpegAudioStream> (*i);
+               assert (ffa);
                _audio_stream->Append (std_to_wx (ffa->name()), new wxStringClientData (std_to_wx (ffa->to_string ())));
        }
        
index 16266f9d5df0bf8e352a112ad639a4ff8f79d35e..eb58899f52019999f032a94ab52434a941005039 100644 (file)
@@ -50,6 +50,7 @@ FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
        , _panel (new wxPanel (this))
        , _slider (new wxSlider (this, wxID_ANY, 0, 0, 4096))
        , _play_button (new wxToggleButton (this, wxID_ANY, wxT ("Play")))
+       , _got_frame (false)
        , _out_width (0)
        , _out_height (0)
        , _panel_width (0)
@@ -101,7 +102,7 @@ FilmViewer::film_changed (Film::Property p)
                o->decode_subtitles = true;
                o->video_sync = false;
                _decoders = decoder_factory (_film, o, 0);
-               _decoders.video->Video.connect (bind (&FilmViewer::process_video, this, _1, _2));
+               _decoders.video->Video.connect (bind (&FilmViewer::process_video, this, _1, _2, _3));
                _decoders.video->OutputChanged.connect (boost::bind (&FilmViewer::decoder_changed, this));
                _decoders.video->set_subtitle_stream (_film->subtitle_stream());
                calculate_sizes ();
@@ -307,12 +308,14 @@ FilmViewer::check_play_state ()
 }
 
 void
-FilmViewer::process_video (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
+FilmViewer::process_video (shared_ptr<Image> image, bool, shared_ptr<Subtitle> sub)
 {
        _raw_frame = image;
        _raw_sub = sub;
 
        raw_to_display ();
+
+       _got_frame = true;
 }
 
 void
@@ -322,8 +325,8 @@ FilmViewer::get_frame ()
        _raw_frame.reset ();
        
        try {
-               shared_ptr<Image> last = _display_frame;
-               while (last == _display_frame) {
+               _got_frame = false;
+               while (!_got_frame) {
                        if (_decoders.video->pass ()) {
                                /* We didn't get a frame before the decoder gave up,
                                   so clear our display frame.
index dbaf8eee268167d558dd9d05c9ee402b1fdce09b..78320781125e51c18b5c69032c7f702d05d47885 100644 (file)
@@ -48,7 +48,7 @@ private:
        void slider_moved (wxScrollEvent &);
        void play_clicked (wxCommandEvent &);
        void timer (wxTimerEvent &);
-       void process_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
+       void process_video (boost::shared_ptr<Image>, bool, boost::shared_ptr<Subtitle>);
        void calculate_sizes ();
        void check_play_state ();
        void update_from_raw ();
@@ -70,6 +70,7 @@ private:
        boost::shared_ptr<Image> _display_frame;
        boost::shared_ptr<RGBPlusAlphaImage> _display_sub;
        Position _display_sub_position;
+       bool _got_frame;
 
        int _out_width;
        int _out_height;
index b9a462801103957b8fbe1cee1e1c4a08ded73377..bc444e4bc2a6370ed54d100cb51f864f17345229 100644 (file)
@@ -33,7 +33,7 @@ using namespace boost;
  *  @param s Sizer to add to.
  *  @param p Parent window for the wxStaticText.
  *  @param t Text for the wxStaticText.
- *  @param prop Properties to pass when calling Add() on the wxSizer.
+ *  @param prop Proportion to pass when calling Add() on the wxSizer.
  */
 wxStaticText *
 add_label_to_sizer (wxSizer* s, wxWindow* p, string t, int prop)