[FFmpeg-devel] [PATCH] hevc: extract SEI caption data

Michael Niedermayer michael at niedermayer.cc
Fri Nov 6 20:02:42 CET 2015


On Thu, Nov 05, 2015 at 08:15:33AM -0600, Will Kelleher wrote:
> Signed-off-by: Will Kelleher <wkelleher at gogoair.com>
> ---
>  libavcodec/hevc.c     | 10 +++++++
>  libavcodec/hevc.h     |  4 +++
>  libavcodec/hevc_sei.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 93 insertions(+)
> 
> diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
> index 4b3f199..1fa5283 100644
> --- a/libavcodec/hevc.c
> +++ b/libavcodec/hevc.c
> @@ -2566,6 +2566,16 @@ static int set_side_data(HEVCContext *s)
>                                 s->sei_hflip, s->sei_vflip);
>      }
>  
> +    if (s->a53_caption) {
> +        AVFrameSideData* sd = av_frame_new_side_data(out,
> +                                                     AV_FRAME_DATA_A53_CC,
> +                                                     s->a53_caption_size);
> +        if (sd)
> +            memcpy(sd->data, s->a53_caption, s->a53_caption_size);
> +        av_freep(&s->a53_caption);
> +        s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
> +    }
> +
>      return 0;
>  }
>  
> diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
> index 66b9a2f..6d8f703 100644
> --- a/libavcodec/hevc.h
> +++ b/libavcodec/hevc.h
> @@ -937,6 +937,10 @@ typedef struct HEVCContext {
>      int sei_hflip, sei_vflip;
>  
>      int picture_struct;
> +
> +    uint8_t* a53_caption;
> +    int a53_caption_size;
> +
>  } HEVCContext;
>  
>  int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,
> diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> index 179b045..0e56859 100644
> --- a/libavcodec/hevc_sei.c
> +++ b/libavcodec/hevc_sei.c
> @@ -146,6 +146,83 @@ static int decode_pic_timing(HEVCContext *s)
>      return 1;
>  }
>  
> +static int decode_registered_user_data_closed_caption(HEVCContext *s, int size)
> +{
> +   int flag;
> +   int user_data_type_code;
> +   int cc_count;
> +
> +   GetBitContext *gb = &s->HEVClc->gb;
> +
> +   if (size < 3)
> +       return AVERROR(EINVAL);
> +
> +   user_data_type_code = get_bits(gb, 8);
> +   if (user_data_type_code == 0x3) {
> +       skip_bits(gb, 1); // reserved
> +
> +       flag = get_bits(gb, 1); // process_cc_data_flag
> +       if (flag) {
> +           skip_bits(gb, 1);
> +           cc_count = get_bits(gb, 5);
> +           skip_bits(gb, 8); // reserved
> +           size -= 2;
> +
> +           if (cc_count && size >= cc_count * 3) {

> +               if (s->a53_caption)
> +                   av_freep(&s->a53_caption);

unneeded null pointer check


> +               s->a53_caption_size = cc_count * 3;
> +

> +               s->a53_caption = av_malloc(s->a53_caption_size);
> +
> +               int i;
> +               for (i = 0; i < s->a53_caption_size; i++) {
> +                   s->a53_caption[i++] = get_bits(gb, 8);

missing malloc failure check


> +               }
> +               skip_bits(gb, 8); // marker_bits
> +           }
> +       }
> +   } else {
> +       int i;

> +       for (i = 0; i < size - 1; i++)
> +           skip_bits(gb, 8);

skip_bits_long()

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151106/437ab687/attachment.sig>


More information about the ffmpeg-devel mailing list