Ticket #2602: ffmpeg-telecine.diff

File ffmpeg-telecine.diff, 3.6 KB (added by MetalThrashingManiac, 6 years ago)

Possible telecine implementation inside mpeg2video enc

  • libavcodec/mpeg12enc.c

    diff -ur a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
    a b  
    228228        s->timecode_frame_start = 0; // default is -1
    229229    }
    230230
     231    if (s->telecine) {
     232        if (s->frame_rate_index != 1 && s->frame_rate_index != 2) {
     233          av_log( avctx, AV_LOG_ERROR, "Telecine is only allowed with 24000/1001 or 24 fps input\n" );
     234          return AVERROR(EINVAL);
     235        }
     236        if (!s->progressive_sequence) {
     237          av_log( avctx, AV_LOG_ERROR, "Telecine is only allowed with progressive input\n" );
     238          return AVERROR(EINVAL);
     239        }
     240    }
     241
    231242    return 0;
    232243}
    233244
     
    275286        }
    276287
    277288        put_bits(&s->pb, 4, s->aspect_ratio_info);
    278         put_bits(&s->pb, 4, s->frame_rate_index);
     289        put_bits(&s->pb, 4, s->frame_rate_index + (s->telecine ? 3 : 0));
    279290
    280291        if (s->avctx->rc_max_rate) {
    281292            v = (s->avctx->rc_max_rate + 399) / 400;
     
    328339            put_bits(&s->pb, 3, s->avctx->profile); // profile
    329340            put_bits(&s->pb, 4, s->avctx->level);   // level
    330341
    331             put_bits(&s->pb, 1, s->progressive_sequence);
     342            put_bits(&s->pb, 1, s->telecine ? 0 : s->progressive_sequence);
    332343            put_bits(&s->pb, 2, s->chroma_format);
    333344            put_bits(&s->pb, 2, s->width  >> 12);
    334345            put_bits(&s->pb, 2, s->height >> 12);
     
    463474
    464475    s->frame_pred_frame_dct = 1;
    465476    if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
     477        if (s->telecine) {
     478            static const int
     479                tff[4] = { 1, 0, 0, 1 },
     480                rff[4] = { 1, 0, 1, 0 };
     481            const size_t mod = picture_number & 0x3;
     482            s->top_field_first = tff[mod];
     483            s->repeat_first_field = rff[mod];
     484        }
    466485        put_header(s, EXT_START_CODE);
    467486        put_bits(&s->pb, 4, 8);                 /* pic ext */
    468487        if (s->pict_type == AV_PICTURE_TYPE_P ||
     
    483502        av_assert0(s->picture_structure == PICT_FRAME);
    484503        put_bits(&s->pb, 2, s->picture_structure);
    485504        if (s->progressive_sequence)
    486             put_bits(&s->pb, 1, 0);            /* no repeat */
     505            put_bits(&s->pb, 1, s->telecine ? s->top_field_first : 0); /* no repeat */
    487506        else
    488507            put_bits(&s->pb, 1, s->current_picture_ptr->f->top_field_first);
    489508        /* XXX: optimize the generation of this flag with entropy measures */
     
    11751194#undef LEVEL
    11761195    FF_MPV_COMMON_OPTS
    11771196    FF_MPEG2_PROFILE_OPTS
     1197    { "telecine", "Apply 3:2 pulldown (soft telecine)", OFFSET(telecine), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
    11781198    { NULL },
    11791199};
    11801200
  • libavcodec/mpegvideo_enc.c

    diff -ur a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
    a b  
    20012001                av_log(avctx, AV_LOG_ERROR,
    20022002                       "Internal error, negative bits\n");
    20032003
    2004             av_assert1(s->repeat_first_field == 0);
     2004            av_assert1(s->repeat_first_field == 0 || s->telecine);
    20052005
    20062006            vbv_delay = bits * 90000 / avctx->rc_max_rate;
    20072007            min_delay = (minbits * 90000LL + avctx->rc_max_rate - 1) /
  • libavcodec/mpegvideo.h

    diff -ur a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
    a b  
    582582    int noise_reduction;
    583583
    584584    int intra_penalty;
     585   
     586    int telecine;
    585587} MpegEncContext;
    586588
    587589/* mpegvideo_enc common options */