Ticket #7515: t7515_srt_subtitle_fix.diff

File t7515_srt_subtitle_fix.diff, 3.5 KB (added by tralph, 11 years ago)

proper fix for SRT subtitles using timecodes

  • libs/libmythtv/NuppelVideoPlayer.cpp

     
    72027202    }
    72037203    else
    72047204    {
    7205         // BEGIN HACK
    7206         // Like frame based subtitles this can get out of sync after
    7207         // transcoding, using the raw timecode doesn't work either
    7208         // with DTV broadcasts where the timecode isn't zero on the
    7209         // first frame, and may roll over during the broadcast.
    7210         playPos = (uint64_t)
    7211             ((currentFrame->frameNumber / video_frame_rate) * 1000);
    7212         // END HACK
     7205        // Use timecodes for time based SRT subtitles. Feeding this into
     7206        // NormalizeVideoTimecode should adjust for non-zero start times
     7207        // and wraps. For MPEG wraps will occur just once every 26.5 hours
     7208        // so this should be sufficient.
     7209        playPos = GetDecoder()->NormalizeVideoTimecode(currentFrame->timecode);
    72137210    }
    72147211
    72157212    if (!textSubtitles.HasSubtitleChanged(playPos))
  • libs/libmythtv/decoderbase.h

     
    113113    virtual bool DoRewind(long long desiredFrame, bool doflush = true);
    114114    virtual bool DoFastForward(long long desiredFrame, bool doflush = true);
    115115
     116    virtual int64_t NormalizeVideoTimecode(int64_t timecode) { return timecode; }
     117
    116118    virtual bool isLastFrameKey() = 0;
    117119    virtual void WriteStoredData(RingBuffer *rb, bool storevid,
    118120                                 long timecodeOffset) = 0;
  • libs/libmythtv/avformatdecoder.cpp

     
    616616    return  ((lsb - base_ts)&mask);
    617617}
    618618
     619int64_t AvFormatDecoder::NormalizeVideoTimecode(int64_t timecode)
     620{
     621    AVStream *st = NULL;
     622    for (uint i = 0; i < ic->nb_streams; i++)
     623    {
     624        AVStream *st1 = ic->streams[i];
     625        if (st1 && st1->codec->codec_type == CODEC_TYPE_VIDEO)
     626        {
     627            st = st1;
     628            break;
     629        }
     630    }
     631    if (!st)
     632        return false;
     633
     634   // convert timecode and start_time to AV_TIME_BASE units
     635   int64_t start_ts = av_rescale(ic->start_time,
     636                                 st->time_base.den,
     637                                 AV_TIME_BASE * (int64_t)st->time_base.num);
     638
     639   int64_t ts = av_rescale(timecode / 1000.0 * AV_TIME_BASE,
     640                           st->time_base.den,
     641                           AV_TIME_BASE * (int64_t)st->time_base.num);
     642
     643   // adjust for start time and wrap
     644   ts = lsb3full(ts, start_ts, st->pts_wrap_bits);
     645
     646   return (int64_t)(av_q2d(st->time_base) * ts * 1000);
     647}
     648
    619649int AvFormatDecoder::GetNumChapters()
    620650{
    621651    return ic->nb_chapters;
  • libs/libmythtv/avformatdecoder.h

     
    141141    virtual bool DoRewind(long long desiredFrame, bool doflush = true);
    142142    virtual bool DoFastForward(long long desiredFrame, bool doflush = true);
    143143
     144    virtual int64_t NormalizeVideoTimecode(int64_t timecode);
     145
    144146    virtual int  GetTeletextDecoderType(void) const;
    145147    virtual void SetTeletextDecoderViewer(TeletextViewer*);
    146148