Ticket #1722: patchpgssub.diff

File patchpgssub.diff, 6.8 KB (added by Carl Eugen Hoyos, 14 years ago)
  • ffmpeg.c

    diff --git a/ffmpeg.c b/ffmpeg.c
    index 4d12f80..c48aec7 100644
    a b static void sub2video_push_ref(InputStream *ist, int64_t pts)  
    202202                             AV_BUFFERSRC_FLAG_PUSH);
    203203}
    204204
    205 static void sub2video_update(InputStream *ist, AVSubtitle *sub, int64_t pts)
     205static void sub2video_update(InputStream *ist, AVSubtitle *sub)
    206206{
    207207    int w = ist->sub2video.w, h = ist->sub2video.h;
    208208    AVFilterBufferRef *ref = ist->sub2video.ref;
    209209    int8_t *dst;
    210210    int     dst_linesize;
    211211    int i;
     212    int64_t pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ist->st->time_base);
    212213
    213214    if (!ref)
    214215        return;
    static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void *  
    693694static void do_subtitle_out(AVFormatContext *s,
    694695                            OutputStream *ost,
    695696                            InputStream *ist,
    696                             AVSubtitle *sub,
    697                             int64_t pts)
     697                            AVSubtitle *sub)
    698698{
    699699    int subtitle_out_max_size = 1024 * 1024;
    700700    int subtitle_out_size, nb, i;
    701701    AVCodecContext *enc;
    702702    AVPacket pkt;
     703    int64_t pts;
    703704
    704     if (pts == AV_NOPTS_VALUE) {
     705    if (sub->pts == AV_NOPTS_VALUE) {
    705706        av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
    706707        if (exit_on_error)
    707708            exit_program(1);
    static void do_subtitle_out(AVFormatContext *s,  
    723724        nb = 1;
    724725
    725726    /* shift timestamp to honor -ss and make check_recording_time() work with -t */
    726     pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q)
    727         - output_files[ost->file_index]->start_time;
     727    pts = sub->pts - output_files[ost->file_index]->start_time;
    728728    for (i = 0; i < nb; i++) {
    729729        ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
    730730        if (!check_recording_time(ost))
    static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)  
    16571657static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
    16581658{
    16591659    AVSubtitle subtitle;
    1660     int64_t pts = pkt->pts;
    16611660    int i, ret = avcodec_decode_subtitle2(ist->st->codec,
    16621661                                          &subtitle, got_output, pkt);
    16631662    if (ret < 0 || !*got_output) {
    static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)  
    16681667
    16691668    if (ist->fix_sub_duration) {
    16701669        if (ist->prev_sub.got_output) {
    1671             int end = av_rescale_q(pts - ist->prev_sub.pts, ist->st->time_base,
    1672                                    (AVRational){ 1, 1000 });
     1670            int end = av_rescale(subtitle.pts - ist->prev_sub.subtitle.pts,
     1671                                 1000, AV_TIME_BASE);
    16731672            if (end < ist->prev_sub.subtitle.end_display_time) {
    16741673                av_log(ist->st->codec, AV_LOG_DEBUG,
    16751674                       "Subtitle duration reduced from %d to %d\n",
    static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)  
    16771676                ist->prev_sub.subtitle.end_display_time = end;
    16781677            }
    16791678        }
    1680         FFSWAP(int64_t,    pts,         ist->prev_sub.pts);
    16811679        FFSWAP(int,        *got_output, ist->prev_sub.got_output);
    16821680        FFSWAP(int,        ret,         ist->prev_sub.ret);
    16831681        FFSWAP(AVSubtitle, subtitle,    ist->prev_sub.subtitle);
    16841682    }
    16851683
     1684    sub2video_update(ist, &subtitle);
     1685
    16861686    if (!*got_output || !subtitle.num_rects)
    16871687        return ret;
    16881688
    16891689    rate_emu_sleep(ist);
    16901690
    1691     sub2video_update(ist, &subtitle, pkt->pts);
    1692 
    16931691    for (i = 0; i < nb_output_streams; i++) {
    16941692        OutputStream *ost = output_streams[i];
    16951693
    16961694        if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
    16971695            continue;
    16981696
    1699         do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle, pts);
     1697        do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle);
    17001698    }
    17011699
    17021700    avsubtitle_free(&subtitle);
  • ffmpeg.h

    diff --git a/ffmpeg.h b/ffmpeg.h
    index cd849c9..85a11a0 100644
    a b typedef struct InputStream {  
    232232
    233233    int fix_sub_duration;
    234234    struct { /* previous decoded subtitle and related variables */
    235         int64_t pts;
    236235        int got_output;
    237236        int ret;
    238237        AVSubtitle subtitle;
  • ffplay.c

    diff --git a/ffplay.c b/ffplay.c
    index 42f03b8..408c82c 100644
    a b static int subtitle_thread(void *arg)  
    18401840
    18411841        avcodec_decode_subtitle2(is->subtitle_st->codec, &sp->sub,
    18421842                                 &got_subtitle, pkt);
     1843        if (sp->sub.pts != AV_NOPTS_VALUE)
     1844            pts = sp->sub.pts / (double)AV_TIME_BASE;
    18431845
    18441846        if (got_subtitle && sp->sub.format == 0) {
    18451847            sp->pts = pts;
  • libavcodec/pgssubdec.c

    diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
    index 79ebb55..64d20df 100644
    a b typedef struct PGSSubContext {  
    6767    PGSSubPresentation presentation;
    6868    uint32_t           clut[256];
    6969    PGSSubPicture      pictures[UINT16_MAX];
     70    int64_t            pts;
    7071    int forced_subs_only;
    7172} PGSSubContext;
    7273
    static int display_end_segment(AVCodecContext *avctx, void *data,  
    387388     *      not been cleared by a subsequent empty display command.
    388389     */
    389390
     391    if (ctx->pts == AV_NOPTS_VALUE) /* if no presentation segment to set it */
     392        ctx->pts = sub->pts;
    390393    memset(sub, 0, sizeof(*sub));
     394    sub->pts = ctx->pts;
     395    ctx->pts = AV_NOPTS_VALUE;
    391396
    392397    // Blank if last object_count was 0.
    393398    if (!ctx->presentation.object_count)
    static int display_end_segment(AVCodecContext *avctx, void *data,  
    436441static int decode(AVCodecContext *avctx, void *data, int *data_size,
    437442                  AVPacket *avpkt)
    438443{
     444    PGSSubContext *ctx = avctx->priv_data;
    439445    const uint8_t *buf = avpkt->data;
    440446    int buf_size       = avpkt->size;
     447    AVSubtitle *sub    = data;
    441448
    442449    const uint8_t *buf_end;
    443450    uint8_t       segment_type;
    static int decode(AVCodecContext *avctx, void *data, int *data_size,  
    482489            break;
    483490        case PRESENTATION_SEGMENT:
    484491            parse_presentation_segment(avctx, buf, segment_length);
     492            ctx->pts = sub->pts;
    485493            break;
    486494        case WINDOW_SEGMENT:
    487495            /*
  • libavcodec/utils.c

    diff --git a/libavcodec/utils.c b/libavcodec/utils.c
    index 99e012a..30b0d21 100644
    a b int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,  
    17011701    avctx->pkt = avpkt;
    17021702    *got_sub_ptr = 0;
    17031703    avcodec_get_subtitle_defaults(sub);
     1704    if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
     1705        sub->pts = av_rescale_q(avpkt->pts,
     1706                                avctx->pkt_timebase, AV_TIME_BASE_Q);
    17041707    ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
    17051708    if (*got_sub_ptr)
    17061709        avctx->frame_number++;