From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 5/6] avformat/matroskaenc: Improve handling of AV1 extradata Date: Tue, 21 Jun 2022 04:34:17 +0200 Message-ID: <DB6PR0101MB221465243AFBE1993221C0728FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw) In-Reply-To: <DB6PR0101MB2214886E62B7920390D6D89F8FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> Up until now, only the first four bytes (the ones preceding the OBU) were written because not enough space has been reserved for the complete CodecPrivate. This commit changes this by increasing the space reserved for the CodecPrivate (it is big enough for every sane sequence header plus something extra); the code falls back to writing four bytes in case the increased space turns out to be insufficient. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/matroskaenc.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 250015419f..b240ca0a06 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -56,6 +56,7 @@ #include "libavutil/samplefmt.h" #include "libavutil/stereo3d.h" +#include "libavcodec/av1.h" #include "libavcodec/xiph.h" #include "libavcodec/mpeg4audio.h" @@ -1117,7 +1118,7 @@ static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn return ff_isom_write_av1c(dyn_cp, extradata, extradata_size, 1); else - *size_to_reserve = 4; + *size_to_reserve = (AV1_SANE_SEQUENCE_HEADER_MAX_BITS + 7) / 8 + 100; break; #if CONFIG_MATROSKA_MUXER case AV_CODEC_ID_FLAC: @@ -1263,7 +1264,7 @@ static void mkv_put_codecprivate(AVIOContext *pb, unsigned max_payload_size, static int mkv_update_codecprivate(AVFormatContext *s, MatroskaMuxContext *mkv, uint8_t *side_data, int side_data_size, AVCodecParameters *par, AVIOContext *pb, - mkv_track *track) + mkv_track *track, unsigned alternative_size) { AVIOContext *const dyn_bc = mkv->tmp_bc; uint8_t *codecpriv; @@ -1275,9 +1276,12 @@ static int mkv_update_codecprivate(AVFormatContext *s, MatroskaMuxContext *mkv, &codecpriv, &codecpriv_size, &max_payload_size); if (ret < 0) goto fail; - if (codecpriv_size > track->codecpriv_size) { + if (codecpriv_size > track->codecpriv_size && !alternative_size) { ret = AVERROR(ENOSPC); goto fail; + } else if (codecpriv_size > track->codecpriv_size) { + av_assert1(alternative_size < track->codecpriv_size); + codecpriv_size = alternative_size; } avio_seek(pb, track->codecpriv_offset, SEEK_SET); mkv_put_codecprivate(pb, track->codecpriv_size, @@ -2702,7 +2706,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) if (!output_sample_rate) output_sample_rate = track->sample_rate; // Space is already reserved, so it's this or a void element. ret = mkv_update_codecprivate(s, mkv, side_data, side_data_size, - par, mkv->track.bc, track); + par, mkv->track.bc, track, 0); if (ret < 0) return ret; avio_seek(mkv->track.bc, track->sample_rate_offset, SEEK_SET); @@ -2722,7 +2726,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) return AVERROR(EINVAL); } ret = mkv_update_codecprivate(s, mkv, side_data, side_data_size, - par, mkv->track.bc, track); + par, mkv->track.bc, track, 0); if (ret < 0) return ret; } @@ -2732,27 +2736,12 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) // See https://bugs.chromium.org/p/aomedia/issues/detail?id=2012 case AV_CODEC_ID_AV1: if (side_data_size && mkv->track.bc && !par->extradata_size) { - AVIOContext *dyn_cp; - uint8_t *codecpriv; - int codecpriv_size; - ret = avio_open_dyn_buf(&dyn_cp); - if (ret < 0) - return ret; - ff_isom_write_av1c(dyn_cp, side_data, side_data_size, 1); - codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv); - if ((ret = dyn_cp->error) < 0 || - !codecpriv_size && (ret = AVERROR_INVALIDDATA)) { - ffio_free_dyn_buf(&dyn_cp); - return ret; - } - avio_seek(mkv->track.bc, track->codecpriv_offset, SEEK_SET); - // Do not write the OBUs as we don't have space saved for them - put_ebml_binary(mkv->track.bc, MATROSKA_ID_CODECPRIVATE, codecpriv, 4); - ffio_free_dyn_buf(&dyn_cp); - ret = ff_alloc_extradata(par, side_data_size); + // If the reserved space doesn't suffice, only write + // the first four bytes of the av1C. + ret = mkv_update_codecprivate(s, mkv, side_data, side_data_size, + par, mkv->track.bc, track, 4); if (ret < 0) return ret; - memcpy(par->extradata, side_data, side_data_size); } else if (!par->extradata_size) return AVERROR_INVALIDDATA; break; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-06-21 2:35 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-06-21 2:30 [FFmpeg-devel] [PATCH 1/6] avformat/matroskaenc: Split assembling CodecPrivate from writing it Andreas Rheinhardt 2022-06-21 2:34 ` [FFmpeg-devel] [PATCH 2/6] avformat/matroskaenc: Avoid swapping codecpar->extradata temporarily Andreas Rheinhardt 2022-06-21 2:34 ` [FFmpeg-devel] [PATCH 3/6] avformat/matroskaenc: Split updating CodecPrivate from writing it Andreas Rheinhardt 2022-06-21 15:22 ` Michael Niedermayer 2022-06-21 21:45 ` Andreas Rheinhardt 2022-06-21 2:34 ` [FFmpeg-devel] [PATCH 4/6] avcodec/av1: Add upper bound for the size of a sane sequence header Andreas Rheinhardt 2022-06-21 2:34 ` Andreas Rheinhardt [this message] 2022-06-21 2:34 ` [FFmpeg-devel] [PATCH 6/6] avformat/matroskaenc: Fix outdated comment Andreas Rheinhardt 2022-06-21 3:22 ` [FFmpeg-devel] [PATCH 7/7] avformat/matroskaenc: Reuse dynamic buffer Andreas Rheinhardt 2022-06-24 9:50 ` [FFmpeg-devel] [PATCH 1/6] avformat/matroskaenc: Split assembling CodecPrivate from writing it Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=DB6PR0101MB221465243AFBE1993221C0728FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git