[FFmpeg-devel] [PATCH 03/10] libavcodec/ccaption_dec: add calculate_duration option
Anshul Maheshwari
anshul.ffmpeg at gmail.com
Fri Jan 8 11:28:02 CET 2016
On Fri, Jan 8, 2016 at 3:51 PM, Anshul Maheshwari <anshul.ffmpeg at gmail.com>
wrote:
>
>
> On Thu, Jan 7, 2016 at 6:10 AM, Aman Gupta <ffmpeg at tmm1.net> wrote:
>
> > Aman Gupta <ffmpeg at tmm1.net> wrote:
>> > > --- a/libavcodec/ccaption_dec.c
>> > > +++ b/libavcodec/ccaption_dec.c
>> > > @@ -150,6 +150,7 @@ struct Screen {
>> > >
>> > > typedef struct CCaptionSubContext {
>> > > AVClass *class;
>> > > + int calculate_duration;
>> > > struct Screen screen[2];
>> > > int active_screen;
>> > > uint8_t cursor_row;
>> > > @@ -545,8 +546,12 @@ static int decode(AVCodecContext *avctx, void
>> > *data, int *got_sub, AVPacket *avp
>> > > continue;
>> > > else
>> > > process_cc608(ctx, *(bptr + i + 1) & 0x7f, *(bptr + i +
>> 2)
>> > & 0x7f);
>> > > - if (ctx->screen_changed)
>> > > - {
>> > > +
>> > > + if (!ctx->screen_changed)
>> > > + continue;
>> > > + ctx->screen_changed = 0;
>> > > +
>> > > + if (ctx->calculate_duration) {
>> > > if (ctx->prev_string) {
>> > > int start_time = av_rescale_q(ctx->prev_time,
>> > avctx->time_base, (AVRational){ 1, 100 });
>> > > int end_time = av_rescale_q(avpkt->pts,
>> > avctx->time_base, (AVRational){ 1, 100 });
>> > > @@ -560,7 +565,12 @@ static int decode(AVCodecContext *avctx, void
>> > *data, int *got_sub, AVPacket *avp
>> > > av_bprintf(&ctx->buffer, "\r\n");
>> > > ctx->prev_string = av_strdup(ctx->buffer.str);
>> > > ctx->prev_time = avpkt->pts;
>> > > - ctx->screen_changed = 0;
>> > > + } else {
>> > > + int start_time = av_rescale_q(avpkt->pts,
>> avctx->time_base,
>> > (AVRational){ 1, 100 });
>> > > + ret = ff_ass_add_rect_bprint(sub, &ctx->buffer,
>> start_time,
>> > -1);
>>
> Is it possible to check the length of buffer, and avoid empty frames.
>
No need, I did understood that they are needed.
>
> > > + if (ret < 0)
>> > > + return ret;
>> > > + sub->pts = av_rescale_q(avpkt->pts, avctx->time_base,
>> > AV_TIME_BASE_Q);
>> > > }
>> > > }
>> > >
>> > > @@ -568,7 +578,10 @@ static int decode(AVCodecContext *avctx, void
>> > *data, int *got_sub, AVPacket *avp
>> > > return ret;
>> > > }
>> > >
>> > > +#define OFFSET(x) offsetof(CCaptionSubContext, x)
>> > > +#define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
>> > > static const AVOption options[] = {
>> > > + { "calculate_duration", "Buffer closed captions to calculate
>> > durations.", OFFSET(calculate_duration), AV_OPT_TYPE_BOOL, { .i64 = 1
>> }, 0,
>> > 1, SD },
>> > > {NULL}
>> > > };
>> > >
>> >
>>
>
>
More information about the ffmpeg-devel
mailing list