[FFmpeg-devel] [PATCH] mpeg12enc: Use Closed Captions if available

Carl Eugen Hoyos ceffmpeg at gmail.com
Thu Feb 7 19:28:58 EET 2019


2019-02-07 17:08 GMT+01:00, Mathieu Duponchelle <mathieu at centricular.com>:
> ---
>  doc/encoders.texi      |  3 +++
>  libavcodec/mpeg12enc.c | 24 ++++++++++++++++++++++++
>  libavcodec/mpegvideo.h |  2 ++
>  3 files changed, 29 insertions(+)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index e86ae69cc5..378a2ca8eb 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -2574,6 +2574,9 @@ Specifies the video_format written into the sequence
> display extension
>  indicating the source of the video pictures. The default is
> @samp{unspecified},
>  can be @samp{component}, @samp{pal}, @samp{ntsc}, @samp{secam} or
> @samp{mac}.
>  For maximum compatibility, use @samp{component}.
> + at item a53cc @var{boolean}
> +Import closed captions (which must be ATSC compatible format) into output.
> +Only the mpeg2 and h264 decoders provide these. Default is 1 (on).
>  @end table
>
>  @section png
> diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
> index d0b458e34b..7cbb5d652f 100644
> --- a/libavcodec/mpeg12enc.c
> +++ b/libavcodec/mpeg12enc.c
> @@ -544,6 +544,30 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s,
> int picture_number)
>          }
>      }
>
> +    if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->a53_cc) {
> +        side_data = av_frame_get_side_data(s->current_picture_ptr->f,
> +            AV_FRAME_DATA_A53_CC);
> +        if (side_data) {

Should you check here if the size is not bigger than a certain maximum
value ...

> +            int i = 0;
> +
> +            put_header (s, USER_START_CODE);
> +
> +            put_bits(&s->pb, 8, 'G');                   // user_identifier
> +            put_bits(&s->pb, 8, 'A');
> +            put_bits(&s->pb, 8, '9');
> +            put_bits(&s->pb, 8, '4');
> +            put_bits(&s->pb, 8, 3);                     //
> user_data_type_code

> +            put_bits(&s->pb, 8,
> +                ((side_data->size / 3) & 0x1f) | 0x40); // flags, cc_count

... because of this calculation?

Carl Eugen


More information about the ffmpeg-devel mailing list