Look up unknown subtitle end times from the data prepared by the examiner.
[dcpomatic.git] / src / lib / util.cc
index 22baa8fd3b920482551231df7037281974d60d49..99d9ba2c4f55654f12e2af866585121b2f6cb92e 100644 (file)
@@ -509,7 +509,7 @@ audio_channel_name (int c)
 bool
 valid_image_file (boost::filesystem::path f)
 {
-       if (boost::starts_with (f.string(), "._")) {
+       if (boost::starts_with (f.leaf().string(), "._")) {
                return false;
        }
                
@@ -546,13 +546,13 @@ tidy_for_filename (string f)
 }
 
 dcp::Size
-fit_ratio_within (float ratio, dcp::Size full_frame, int round)
+fit_ratio_within (float ratio, dcp::Size full_frame)
 {
        if (ratio < full_frame.ratio ()) {
-               return dcp::Size (round_to (full_frame.height * ratio, round), full_frame.height);
+               return dcp::Size (rint (full_frame.height * ratio), full_frame.height);
        }
        
-       return dcp::Size (full_frame.width, round_to (full_frame.width / ratio, round));
+       return dcp::Size (full_frame.width, rint (full_frame.width / ratio));
 }
 
 void *
@@ -564,18 +564,21 @@ wrapped_av_malloc (size_t s)
        }
        return p;
 }
-               
-ContentTimePeriod
+
+FFmpegSubtitlePeriod
 subtitle_period (AVSubtitle const & sub)
 {
        ContentTime const packet_time = ContentTime::from_seconds (static_cast<double> (sub.pts) / AV_TIME_BASE);
 
-       ContentTimePeriod period (
+       if (sub.end_display_time == static_cast<uint32_t> (-1)) {
+               /* End time is not known */
+               return FFmpegSubtitlePeriod (packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3));
+       }
+       
+       return FFmpegSubtitlePeriod (
                packet_time + ContentTime::from_seconds (sub.start_display_time / 1e3),
                packet_time + ContentTime::from_seconds (sub.end_display_time / 1e3)
                );
-
-       return period;
 }
 
 map<string, string>
@@ -667,3 +670,4 @@ write_frame_info (FILE* file, int frame, Eyes eyes, dcp::FrameInfo info)
        fwrite (&info.size, sizeof (info.size), 1, file);
        fwrite (info.hash.c_str(), 1, info.hash.size(), file);
 }
+