[FFmpeg-devel] [PATCH 2/3] libavcodec/ccaption_dec: in realtime mode, emit new ASS events every 200ms

Aman Gupta ffmpeg at tmm1.net
Wed Jan 6 20:35:11 CET 2016


From: Aman Gupta <aman at tmm1.net>

---
 libavcodec/ccaption_dec.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 706da16..737c3f6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -159,6 +159,7 @@ typedef struct CCaptionSubContext {
     uint8_t cursor_font;
     AVBPrint buffer;
     int screen_reaped;
+    int screen_touched;
     int rollup;
     enum cc_mode mode;
     char *prev_string;
@@ -487,6 +488,7 @@ static void process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
         case 0x2c:
             /* erase display memory */
             handle_erase(ctx, ctx->active_screen);
+            ctx->screen_touched = 1;
             break;
         case 0x2d:
             /* carriage return */
@@ -513,6 +515,8 @@ static void process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
     } else if (hi >= 0x20) {
         /* Standard characters (always in pairs) */
         handle_char(ctx, hi, lo);
+        if (ctx->mode != CCMODE_POPON)
+            ctx->screen_touched = 1;
     } else {
         /* Ignoring all other non data code */
         ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
@@ -577,9 +581,23 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
             if (ret < 0)
                 return ret;
             sub->pts = av_rescale_q(avpkt->pts, avctx->time_base, AV_TIME_BASE_Q);
+            ctx->prev_time = avpkt->pts;
         }
     }
 
+    if (!ctx->calculate_duration && ctx->screen_touched &&
+        avpkt->pts > ctx->prev_time + av_rescale_q(20, ass_tb, avctx->time_base)) {
+        ctx->screen_touched = 0;
+
+        reap_screen(ctx);
+        ctx->screen_reaped = 0;
+
+        int start_time = av_rescale_q(avpkt->pts, avctx->time_base, ass_tb);
+        ff_ass_add_rect_bprint(sub, &ctx->buffer, start_time, -1);
+        sub->pts = av_rescale_q(avpkt->pts, avctx->time_base, AV_TIME_BASE_Q);
+        ctx->prev_time = avpkt->pts;
+    }
+
     *got_sub = sub->num_rects > 0;
     return ret;
 }
-- 
2.5.3



More information about the ffmpeg-devel mailing list