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}
 };
 
-- 
2.5.3

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to