From be579c426d2a6c769e59cc1f5d6adf4416813c4a Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Sat, 23 Mar 2019 00:24:25 +0100 Subject: [PATCH] avvidenc: pass Closed Caption metadata to libav --- ext/libav/gstavvidenc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ext/libav/gstavvidenc.c b/ext/libav/gstavvidenc.c index 6a9ab5bcf5..ab44e9d88f 100644 --- a/ext/libav/gstavvidenc.c +++ b/ext/libav/gstavvidenc.c @@ -517,6 +517,25 @@ stereo_gst_to_av (GstVideoMultiviewMode mview_mode) return AV_STEREO3D_2D; } +static void +gst_ffmpegvidenc_add_cc (GstBuffer * buffer, AVFrame * picture) +{ + GstVideoCaptionMeta *cc_meta; + gpointer iter = NULL; + + while ((cc_meta = + (GstVideoCaptionMeta *) gst_buffer_iterate_meta_filtered (buffer, + &iter, GST_VIDEO_CAPTION_META_API_TYPE))) { + AVFrameSideData *sd; + + if (cc_meta->caption_type != GST_VIDEO_CAPTION_TYPE_CEA708_RAW) + continue; + + sd = av_frame_new_side_data (picture, AV_FRAME_DATA_A53_CC, cc_meta->size); + memcpy (sd->data, cc_meta->data, cc_meta->size); + } +} + static GstFlowReturn gst_ffmpegvidenc_send_frame (GstFFMpegVidEnc * ffmpegenc, GstVideoCodecFrame * frame) @@ -533,6 +552,8 @@ gst_ffmpegvidenc_send_frame (GstFFMpegVidEnc * ffmpegenc, picture = ffmpegenc->picture; + gst_ffmpegvidenc_add_cc (frame->input_buffer, picture); + if (ffmpegenc->context->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME)) { picture->interlaced_frame = TRUE;