X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fffmpeg_decoder.cc;h=253272e9638a3387f529b7d5548eff86321ddaf6;hb=5d6e2ffca8e4b0d587eff8723716003a6d81be47;hp=a0965dcfb81a917eef2e0ba46b1223d536f35cc6;hpb=b0f4faaa75ff563cdc8133d396c1b45456bde4ce;p=dcpomatic.git diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index a0965dcfb..253272e96 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -421,6 +421,12 @@ FFmpegDecoder::decode_audio_packet () ct += ContentTime::from_frames (remove, (*stream)->frame_rate ()); } + if (ct < ContentTime()) { + LOG_WARNING ("Crazy timestamp %s", to_string (ct)); + } + + update_position (ct); + /* Give this data provided there is some, and its time is sane */ if (ct >= ContentTime() && data->frames() > 0) { audio->give (*stream, data, ct); @@ -472,6 +478,7 @@ FFmpegDecoder::decode_video_packet () shared_ptr (new RawImageProxy (image)), llrint (pts * _ffmpeg_content->active_video_frame_rate ()) ); + update_position (ContentTime::from_seconds (pts)); } else { LOG_WARNING_NC ("Dropping frame without PTS"); } @@ -502,6 +509,7 @@ FFmpegDecoder::decode_subtitle_packet () FFmpegSubtitlePeriod sub_period = subtitle_period (sub); ContentTimePeriod period; period.from = sub_period.from + _pts_offset; + update_position (period.from); if (sub_period.to) { /* We already know the subtitle period `to' time */ period.to = sub_period.to.get() + _pts_offset; @@ -604,12 +612,13 @@ FFmpegDecoder::decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimeP out_p += image->stride()[0] / sizeof (uint32_t); } - dcp::Size const vs = _ffmpeg_content->video->size (); + int const target_width = subtitle_codec_context()->width; + int const target_height = subtitle_codec_context()->height; dcpomatic::Rect const scaled_rect ( - static_cast (rect->x) / vs.width, - static_cast (rect->y) / vs.height, - static_cast (rect->w) / vs.width, - static_cast (rect->h) / vs.height + static_cast (rect->x) / target_width, + static_cast (rect->y) / target_height, + static_cast (rect->w) / target_width, + static_cast (rect->h) / target_height ); subtitle->give_image (period, image, scaled_rect); @@ -635,3 +644,16 @@ FFmpegDecoder::decode_ass_subtitle (string ass, ContentTimePeriod period) subtitle->give_text (period, i); } } + +void +FFmpegDecoder::update_position (ContentTime p) +{ + /* _position should err on the side of being too big, as then there is less + chance that we will erroneously decide not to seek when _position > request. + */ + if (!_position) { + _position = p; + } else { + _position = max (*_position, p); + } +}