diff options
author | Mathieu Duponchelle <mathieu@centricular.com> | 2019-02-09 01:10:12 +0300 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2019-03-16 02:02:23 +0300 |
commit | 6cfa17330317346d7ca34525003cad4d96ecf0cd (patch) | |
tree | 2a42662780ee62db8b29c88d1343215dfe2f0640 /libavcodec/mpeg12enc.c | |
parent | def18ac43bb95d2062081c6cac23208456fee03c (diff) |
mpeg12enc: Use Closed Captions if available
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/mpeg12enc.c')
-rw-r--r-- | libavcodec/mpeg12enc.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index d0b458e34b..2bc5289d63 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -61,6 +61,8 @@ static uint32_t mpeg1_chr_dc_uni[512]; static uint8_t mpeg1_index_run[2][64]; static int8_t mpeg1_max_level[2][64]; +#define A53_MAX_CC_COUNT 0x1f + static av_cold void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len) { int i; @@ -544,6 +546,36 @@ 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) { + if (side_data->size <= A53_MAX_CC_COUNT * 3 && side_data->size % 3 == 0) { + 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 & A53_MAX_CC_COUNT) | 0x40); // flags, cc_count + put_bits(&s->pb, 8, 0xff); // em_data + + for (i = 0; i < side_data->size; i++) + put_bits(&s->pb, 8, side_data->data[i]); + + put_bits(&s->pb, 8, 0xff); // marker_bits + } else { + av_log(s->avctx, AV_LOG_WARNING, + "Warning Closed Caption size (%d) can not exceed 93 bytes " + "and must be a multiple of 3\n", side_data->size); + } + } + } + s->mb_y = 0; ff_mpeg1_encode_slice_header(s); } |