Coalesce short reels.
[dcpomatic.git] / src / lib / film.cc
index 5556c8e680ebd39595db3a4748aef4b81e14692b..ed2c5a3725946e23dee1c03f5628de8e1cec6cf1 100644 (file)
@@ -1254,11 +1254,13 @@ Film::move_content_later (shared_ptr<Content> c)
        _playlist->move_later (shared_from_this(), c);
 }
 
-/** @return length of the film from time 0 to the last thing on the playlist */
+/** @return length of the film from time 0 to the last thing on the playlist,
+ *  with a minimum length of 1 second.
+ */
 DCPTime
 Film::length () const
 {
-       return _playlist->length(shared_from_this()).ceil(video_frame_rate());
+       return max(DCPTime::from_seconds(1), _playlist->length(shared_from_this()).ceil(video_frame_rate()));
 }
 
 int
@@ -1641,13 +1643,17 @@ Film::reels () const
                split_points.sort ();
                split_points.unique ();
 
-               /* Make them into periods */
+               /* Make them into periods, coalescing any that are less than 1 second long */
                optional<DCPTime> last;
                BOOST_FOREACH (DCPTime t, split_points) {
-                       if (last) {
+                       if (last && (t - *last) >= DCPTime::from_seconds(1)) {
+                               /* Period from *last to t is long enough; use it and start a new one */
                                p.push_back (DCPTimePeriod(*last, t));
+                               last = t;
+                       } else if (!last) {
+                               /* That was the first time, so start a new period */
+                               last = t;
                        }
-                       last = t;
                }
                break;
        }