Fix hanging subtitles after recent changes to subtitle examination.
authorCarl Hetherington <cth@carlh.net>
Wed, 23 Nov 2016 09:54:16 +0000 (09:54 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 23 Nov 2016 09:54:16 +0000 (09:54 +0000)
src/lib/ffmpeg_examiner.cc
src/lib/ffmpeg_subtitle_stream.cc
src/lib/ffmpeg_subtitle_stream.h

index 271180d5d0970521e58e45f45fa087131abca9d3..eb02ba17be9a2eb5a6abc48b814d90dae8b19836 100644 (file)
@@ -160,21 +160,10 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
        /* Finish off any hanging subtitles at the end */
        for (LastSubtitleMap::const_iterator i = _last_subtitle_start.begin(); i != _last_subtitle_start.end(); ++i) {
                if (i->second) {
-                       if (i->second->image) {
-                               i->first->add_image_subtitle (
+                       if (i->first->unknown_to (i->second->id)) {
+                               i->first->set_subtitle_to (
                                        i->second->id,
-                                       ContentTimePeriod (
-                                               i->second->time,
-                                               ContentTime::from_frames (video_length(), video_frame_rate().get_value_or (24))
-                                               )
-                                       );
-                       } else {
-                               i->first->add_text_subtitle (
-                                       i->second->id,
-                                       ContentTimePeriod (
-                                               i->second->time,
-                                               ContentTime::from_frames (video_length(), video_frame_rate().get_value_or (24))
-                                               )
+                                       ContentTime::from_frames (video_length(), video_frame_rate().get_value_or (24))
                                        );
                        }
                }
index 57c54e1eabaec21ea42b379dbc375e82d90bbcb6..d389714e9e0c5ef9f194432e88bc34dfd08e2a82 100644 (file)
@@ -181,6 +181,23 @@ FFmpegSubtitleStream::find_subtitle_to (string id) const
        return i->second.to;
 }
 
+/** @param id Subtitle id.
+ *  @return true if the `from' and `to' times for this id are equal, which indicates
+ *  that the `to' time is unknown.
+ */
+bool
+FFmpegSubtitleStream::unknown_to (string id) const
+{
+       PeriodMap::const_iterator i = _image_subtitles.find (id);
+       if (i != _image_subtitles.end ()) {
+               return i->second.from == i->second.to;
+       }
+
+       i = _text_subtitles.find (id);
+       DCPOMATIC_ASSERT (i != _text_subtitles.end ());
+       return i->second.from == i->second.to;
+}
+
 /** Add some offset to all the times in the stream */
 void
 FFmpegSubtitleStream::add_offset (ContentTime offset)
index 33247558f29a731871875b3f6de9a4aaaa1b03e8..7c4f8cd396695e55e9fe0fa62d539984ad362575 100644 (file)
@@ -37,6 +37,7 @@ public:
        void add_image_subtitle (std::string id, ContentTimePeriod period);
        void add_text_subtitle (std::string id, ContentTimePeriod period);
        void set_subtitle_to (std::string id, ContentTime to);
+       bool unknown_to (std::string id) const;
        std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod period, bool starting) const;
        std::list<ContentTimePeriod> text_subtitles_during (ContentTimePeriod period, bool starting) const;
        ContentTime find_subtitle_to (std::string id) const;