The new "calculate_duration" option in this patch defaults to true, to preserve the existing behavior. You can set it to false to get the new realtime behavior. This seems a little backwards, so if someone has a better name for this new behavior I'd be interested to hear it. Maybe the option can be called "realtime" and default to false?
Here's an example of the old and new optional behavior: $ ffmpeg -y -nostats -f lavfi -i 'movie=input.ts[out0+subcc]' -map s -f ass - Dialogue: 0,0:00:02.70,0:00:07.47,Default,,0,0,0,,- HEY, THINGS ACTUALLY TURNED\NOUT OKAY FOR ME THIS TIME. Dialogue: 0,0:00:07.47,0:00:08.61,Default,,0,0,0,,- BUTTERS! Dialogue: 0,0:00:08.61,0:00:10.48,Default,,0,0,0,,- OH, I KNOW. Dialogue: 0,0:00:10.48,0:00:41.64,Default,,0,0,0,,Captioning by CaptionMax\ Nwww.captionmax.com Dialogue: 0,0:00:41.64,0:00:42.28,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR, Dialogue: 0,0:00:42.28,0:00:43.91,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR,\NEVERYBODY, TONIGHT WE'LL COVER Dialogue: 0,0:00:43.91,0:00:45.18,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS WE MISSED OVER THE $ ffmpeg -y -calculate_duration 0 -nostats -f lavfi -i 'movie=input.ts[out0+subcc]' -map s -f ass - Dialogue: 0,0:00:00.20,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:00.27,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:02.64,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:02.70,999:59:59.99,Default,,0,0,0,,- HEY, THINGS ACTUALLY TURNED\NOUT OKAY FOR ME THIS TIME. Dialogue: 0,0:00:07.41,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:07.47,999:59:59.99,Default,,0,0,0,,- BUTTERS! Dialogue: 0,0:00:08.54,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:08.61,999:59:59.99,Default,,0,0,0,,- OH, I KNOW. Dialogue: 0,0:00:10.41,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:10.48,999:59:59.99,Default,,0,0,0,,Captioning by CaptionMax\Nwww.captionmax.com Dialogue: 0,0:00:13.48,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:41.07,999:59:59.99,Default,,0,0,0,, Dialogue: 0,0:00:41.27,999:59:59.99,Default,,0,0,0,,>> Trevor Dialogue: 0,0:00:41.47,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW Dialogue: 0,0:00:41.64,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR, Dialogue: 0,0:00:41.84,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR,\NEVERYBODY, Dialogue: 0,0:00:42.04,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR,\NEVERYBODY, TONIGHT WE Dialogue: 0,0:00:42.24,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR,\NEVERYBODY, TONIGHT WE'LL COVER Dialogue: 0,0:00:42.28,999:59:59.99,Default,,0,0,0,,>> Trevor: HAPPY NEW YEAR,\NEVERYBODY, TONIGHT WE'LL COVER Dialogue: 0,0:00:42.48,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS W Dialogue: 0,0:00:42.68,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS WE Dialogue: 0,0:00:43.01,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS WE M Dialogue: 0,0:00:43.21,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS WE MISSED OVER Dialogue: 0,0:00:43.41,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS WE MISSED OVER THE Dialogue: 0,0:00:43.91,999:59:59.99,Default,,0,0,0,,EVERYBODY, TONIGHT WE'LL COVER\NTHE NEWS WE MISSED OVER THE On Wed, Jan 6, 2016 at 2:37 AM, wm4 <nfx...@googlemail.com> wrote: > On Tue, 5 Jan 2016 23:41:35 -0800 > Aman Gupta <ffm...@tmm1.net> wrote: > > > From: Aman Gupta <a...@tmm1.net> > > > > new option defaults to true, to preserve existing behavior. by flipping > > the option to false, subtitle events are emitted as soon as they are > > received and have an infinite duration. > > > > this new mode is useful for realtime decoding of closed captions so they > > can be display along with decoded mpeg2 frames. > > --- > > libavcodec/ccaption_dec.c | 19 ++++++++++++++++--- > > 1 file changed, 16 insertions(+), 3 deletions(-) > > > > diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c > > index f651c88..9f17e77 100644 > > --- 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); > > + 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} > > }; > > > > I want to note that this is actually the only way to get realtime > closed captions (playback, or even just transcoding with rendering > subtitles to the video). Without this, the API user would have to > buffer video and audio frames until the closed caption even is "done". > > Returning events with infinite duration is a hack and a weakness in the > API. These events can't be used with libass in a simple way. Instead, > the API user has to adjust or delete previous events manually. Not > really ideal. > > I'm not sure what a better API could look like. > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel