[FFmpeg-devel] [PATCH 2/3] avcodec/ccaption_dec: allow selection of second field captions

Paul B Mahol onemda at gmail.com
Fri Jun 19 17:26:49 EEST 2020


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavcodec/ccaption_dec.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index e67a47508c..fe6933ab5c 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -224,6 +224,7 @@ struct Screen {
 typedef struct CCaptionSubContext {
     AVClass *class;
     int real_time;
+    int data_field;
     struct Screen screen[2];
     int active_screen;
     uint8_t cursor_row;
@@ -789,11 +790,15 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
     bptr = avpkt->data;
 
     for (i = 0; i < len; i += 3) {
-        uint8_t cc_type = *(bptr + i) & 3;
+        uint8_t cc_type = bptr[i] & 1;
+
         if (validate_cc_data_pair(bptr + i))
             continue;
-        /* ignoring data field 1 */
-        if (cc_type == 1)
+
+        if (ctx->data_field < 0)
+            ctx->data_field = cc_type;
+
+        if (cc_type != ctx->data_field)
             continue;
 
         ret = process_cc608(ctx, bptr[i + 1] & 0x7f, bptr[i + 2] & 0x7f);
@@ -861,6 +866,10 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
     { "real_time", "emit subtitle events as they are decoded for real-time display", OFFSET(real_time), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, SD },
+    { "data_field", "select data field", OFFSET(data_field), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, SD, "data_field" },
+    { "auto",   "pick first one that appears", 0, AV_OPT_TYPE_CONST, { .i64 =-1 }, 0, 0, SD, "data_field" },
+    { "first",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, SD, "data_field" },
+    { "second", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, SD, "data_field" },
     {NULL}
 };
 
-- 
2.17.1



More information about the ffmpeg-devel mailing list