}
shared_ptr<Subtitle> sub;
- if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / rint (_fs->frames_per_second()))) {
+ if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / _fs->frames_per_second())) {
sub = _timed_subtitle->subtitle ();
}
process_audio (_frame->data[0], data_size);
}
- } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _opt->decode_subtitles) {
+ } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _opt->decode_subtitles && _first_video) {
int got_subtitle;
AVSubtitle sub;
no AVSubtitleRects.
*/
if (sub.num_rects > 0) {
- process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub)));
+ process_subtitle (shared_ptr<TimedSubtitle> (new TimedSubtitle (sub, _first_video.get())));
}
avsubtitle_free (&sub);
}
/** Construct a TimedSubtitle. This is a subtitle image, position,
* and a range of time over which it should be shown.
* @param sub AVSubtitle to read.
+ * @param c Fractional seconds that should be subtracted from the AVSubtitle's PTS.
*/
-TimedSubtitle::TimedSubtitle (AVSubtitle const & sub)
+TimedSubtitle::TimedSubtitle (AVSubtitle const & sub, double c)
{
assert (sub.rects > 0);
/* subtitle PTS in seconds */
- float const packet_time = (sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6;
+ double const packet_time = ((sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6) - c;
/* hence start time for this sub */
_from = packet_time + (double (sub.start_display_time) / 1e3);
class TimedSubtitle
{
public:
- TimedSubtitle (AVSubtitle const &);
+ TimedSubtitle (AVSubtitle const &, double c);
bool displayed_at (double t) const;