From: Nuo Mi <nuomi2021@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Nuo Mi <nuomi2021@gmail.com> Subject: [FFmpeg-devel] [PATCH v5 5/6] avformat/mpegtsenc: refact out h26x_prefix_aud Date: Tue, 30 Jan 2024 20:49:02 +0800 Message-ID: <TYSPR06MB643314EF804DCD927A080D36AA7D2@TYSPR06MB6433.apcprd06.prod.outlook.com> (raw) In-Reply-To: <20240130124903.16892-1-nuomi2021@gmail.com> --- libavformat/mpegtsenc.c | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 3872be0f46..7bc3feaef1 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1834,6 +1834,21 @@ static int opus_get_packet_samples(AVFormatContext *s, AVPacket *pkt) return duration; } +static uint8_t *h26x_prefix_aud(const uint8_t *aud, const int aud_size, + const uint8_t *extra_data, const int extra_size, AVPacket *pkt, int *size) +{ + const int sz = 4; //start code size + uint8_t *data = av_malloc(pkt->size + sz + aud_size + extra_size); + if (!data) + return NULL; + AV_WB32(data, 0x00000001); + memcpy(data + sz, aud, aud_size); + memcpy(data + sz + aud_size, extra_data, extra_size); + memcpy(data + sz + aud_size + extra_size, pkt->data, pkt->size); + *size = pkt->size + sz + aud_size + extra_size; + return data; +} + #define H264_NAL_TYPE(state) (state & 0x1f) #define HEVC_NAL_TYPE(state) ((state & 0x7e) >> 1) static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) @@ -1915,16 +1930,14 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) if (!found_aud) { /* Prefix 'buf' with the missing AUD, and extradata if needed. */ - data = av_malloc(pkt->size + 6 + extradd); + const uint8_t aud[] = { + H264_NAL_AUD, + 0xf0, // any slice type (0xe) + rbsp stop one bit + }; + buf = data = h26x_prefix_aud(aud, FF_ARRAY_ELEMS(aud), + st->codecpar->extradata, extradd, pkt, &size); if (!data) return AVERROR(ENOMEM); - memcpy(data + 6, st->codecpar->extradata, extradd); - memcpy(data + 6 + extradd, pkt->data, pkt->size); - AV_WB32(data, 0x00000001); - data[4] = H264_NAL_AUD; - data[5] = 0xf0; // any slice type (0xe) + rbsp stop one bit - buf = data; - size = pkt->size + 6 + extradd; } else if (extradd != 0) { /* Move the AUD up to the beginning of the frame, where the H.264 * spec requires it to appear. Emit the extradata after it. */ @@ -1999,17 +2012,15 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) if (nal_type < HEVC_NAL_BLA_W_LP || nal_type >= HEVC_NAL_RSV_VCL24) extradd = 0; if (nal_type != HEVC_NAL_AUD) { // AUD NAL - data = av_malloc(pkt->size + 7 + extradd); + const uint8_t aud[] = { + (HEVC_NAL_AUD << 1), + 0x01, + 0x50, // any slice type (0x4) + rbsp stop one bit + }; + buf = data = h26x_prefix_aud(aud, FF_ARRAY_ELEMS(aud), + st->codecpar->extradata, extradd, pkt, &size); if (!data) return AVERROR(ENOMEM); - memcpy(data + 7, st->codecpar->extradata, extradd); - memcpy(data + 7 + extradd, pkt->data, pkt->size); - AV_WB32(data, 0x00000001); - data[4] = (HEVC_NAL_AUD << 1); - data[5] = 1; - data[6] = 0x50; // any slice type (0x4) + rbsp stop one bit - buf = data; - size = pkt->size + 7 + extradd; } } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { if (pkt->size < 2) { -- 2.25.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:[~2024-01-30 12:51 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <20240130124903.16892-1-nuomi2021@gmail.com> 2024-01-30 12:48 ` [FFmpeg-devel] [PATCH v5 1/6] avformat/mp4: add muxer support for H266/VVC Nuo Mi 2024-01-30 12:48 ` [FFmpeg-devel] [PATCH v5 2/6] avformat/mpegtsenc: refact mpegts_check_bitstream to loop up table Nuo Mi 2024-01-30 12:49 ` [FFmpeg-devel] [PATCH v5 3/6] avformat/mpegtsenc: refact, move h264, hevc startcode checking to check_h26x_startcode Nuo Mi 2024-01-30 12:49 ` [FFmpeg-devel] [PATCH v5 4/6] avformat/mpegtsenc: refact, remove h264, hevc magic numbers for nal_type Nuo Mi 2024-01-30 12:49 ` Nuo Mi [this message] 2024-01-30 12:49 ` [FFmpeg-devel] [PATCH v5 6/6] avformat/mpegts: add ts stream types for H266/VVC Nuo Mi
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=TYSPR06MB643314EF804DCD927A080D36AA7D2@TYSPR06MB6433.apcprd06.prod.outlook.com \ --to=nuomi2021@gmail.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