[FFmpeg-devel] [PATCH v2 1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata
Marton Balint
cus at passwd.hu
Sun Apr 11 13:41:32 EEST 2021
On Sat, 10 Apr 2021, zheng qian wrote:
> Changes since v1:
> If desc_len < 3, break the switch statement instead of return AVERROR_INVALIDDATA
> to make it more robust.
> For arib_caption, data_component_descriptor should contains at least 3 bytes:
> data_component_id: uint16, additional_arib_caption_info: uint8.
>
> The recognization of ARIB STD-B24 caption has been introduced in commit a03885b,
> which is used as closed caption in Japanese / Brazilian Digital Television.
>
> But whenever copying arib_caption into mpegts output, arib_caption inside the
> outputted stream cannot be recgonized as a arib_caption subtitle track once again,
> which is caused by the missing of descriptors in the PMT table.
>
> These patches are intended to fix broken stream copying of arib_caption subtitle.
>
> This patch extracts necessary fields into codecpar->extradata for future remuxing,
> which describe the stream_identifier, the profile and other additional information.
>
> Signed-off-by: zheng qian <xqq at xqq.im>
> ---
> libavformat/mpegts.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 6e0d9d7496..fd7ea1f504 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -2107,6 +2107,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
> // STD-B24, fascicle 3, chapter 4 defines private_stream_1
> // for captions
> if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
> + if (desc_len < 3)
> + break;
> +
> // This structure is defined in STD-B10, part 1, listing 5.4 and
> // part 2, 6.2.20).
> // Listing of data_component_ids is in STD-B10, part 2, Annex J.
> @@ -2145,6 +2148,28 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
> st->codecpar->codec_id = AV_CODEC_ID_ARIB_CAPTION;
> st->codecpar->profile = picked_profile;
> st->internal->request_probe = 0;
> +
> + // Store stream_identifier and payload of data_component_descriptor
> + // (data_component_id & additional_arib_caption_info) as extradata.
> + // data_component_descriptor is defined in ARIB STD-B10, part 2, 6.2.20
> + // These will be useful for remuxing arib_caption into mpegts output.
> + if (!st->codecpar->extradata) {
> + st->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE);
> + if (!st->codecpar->extradata)
> + return AVERROR(ENOMEM);
> +
> + st->codecpar->extradata_size = 4;
> +
> + // stream_identifier (component_tag of stream_identifier_descriptor)
> + st->codecpar->extradata[0] = (uint8_t)(st->stream_identifier - 1);
Storing this in extradata seems redundant. AVStream->stream_identifier
already exists, and you should be able to use that for muxing as well.
Regards,
Marton
> +
> + // payload of data_component_descriptor structure
> + // data_component_id
> + st->codecpar->extradata[1] = (uint8_t)((data_component_id & 0xF0) >> 8);
> + st->codecpar->extradata[2] = (uint8_t)(data_component_id & 0x0F);
> + // additional_arib_caption_info, defined in ARIB STD-B24, fascicle 1, Part 3, 9.6.1
> + st->codecpar->extradata[3] = get8(pp, desc_end);
> + }
> }
> break;
> case 0xb0: /* DOVI video stream descriptor */
> --
> 2.29.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list