Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / lib / writer.cc
index 675f210e9e469535a10c30385974d194bccc0d3a..47c6b838142619a355cab1f0fbc298f84586df9b 100644 (file)
@@ -473,11 +473,11 @@ Writer::finish ()
 
        BOOST_FOREACH (ReelWriter& i, _reels) {
 
-               cpl->add (i.create_reel (_reel_assets, _fonts));
-
                shared_ptr<Job> job = _job.lock ();
                DCPOMATIC_ASSERT (job);
                i.calculate_digests (job);
+
+               cpl->add (i.create_reel (_reel_assets, _fonts));
        }
 
        dcp::XMLMetadata meta;
@@ -570,7 +570,16 @@ operator== (QueueItem const & a, QueueItem const & b)
 void
 Writer::set_encoder_threads (int threads)
 {
-       _maximum_frames_in_memory = lrint (threads * 1.1);
+       /* I think the scaling factor here should be the ratio of the longest frame
+          encode time to the shortest; if the thread count is T, longest time is L
+          and the shortest time S we could encode L/S frames per thread whilst waiting
+          for the L frame to encode so we might have to store LT/S frames.
+
+          However we don't want to use too much memory, so keep it a bit lower than we'd
+          perhaps like.  A J2K frame is typically about 1Mb so 3 here will mean we could
+          use about 240Mb with 72 encoding threads.
+       */
+       _maximum_frames_in_memory = lrint (threads * 3);
 }
 
 void