History

avcodec/bsf/h264_mp4toannexb: Fix mixed bitstream format

This bsf converts AV_PKT_DATA_NEW_EXTRADATA side data in avcc format to in-band annexb format. However, the side data wasn't been removed and copied from input packet to output packet. So the output packet has mixed bitstream format. We don't support mixed bitstream format. For example, h264_metadata report error in the following case: ffmpeg -i foo.flv \ -bsf:v "h264_mp4toannexb,h264_metadata" \ -c copy -f null This patch removed NEW_EXTRADATA side data after process. This patch also add a check so only NEW_EXTRADATA in avcc format is processed. NEW_EXTRADATA in annexb format is copied to output as is.

Zhao Zhili committed 1 year ago

Commit 25812d31 parent 26752362 files · +14 −12Browse files

Unified · Split

2 files
  1. libavcodec/bsf/h264_mp4toannexb.c +12 −10
  2. tests/fate/h264.mak +2 −2
libavcodec/bsf/h264_mp4toannexb.c+12−10
@@ -93,6 +93,11 @@ static int h264_extradata_to_annexb(AVBSFContext *ctx, · 92 unmodified lines
93 const int padding = AV_INPUT_BUFFER_PADDING_SIZE;93 const int padding = AV_INPUT_BUFFER_PADDING_SIZE;
94 int length_size, pps_offset = 0;94 int length_size, pps_offset = 0;
95 95
96 if (extradata_size < 7) {
97 av_log(ctx, AV_LOG_ERROR, "Invalid extradata size: %d\n", extradata_size);
98 return AVERROR_INVALIDDATA;
99 }
100
96 bytestream2_init(gb, extradata, extradata_size);101 bytestream2_init(gb, extradata, extradata_size);
97 102
98 bytestream2_skipu(gb, 4);103 bytestream2_skipu(gb, 4);
@@ -262,16 +267,11 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx) · 163 unmodified lines
262 (extra_size >= 4 && AV_RB32(ctx->par_in->extradata) == 1)) {267 (extra_size >= 4 && AV_RB32(ctx->par_in->extradata) == 1)) {
263 av_log(ctx, AV_LOG_VERBOSE,268 av_log(ctx, AV_LOG_VERBOSE,
264 "The input looks like it is Annex B already\n");269 "The input looks like it is Annex B already\n");
265 } else if (extra_size >= 7) {270 return 0;
266 return h264_extradata_to_annexb(ctx,
267 ctx->par_in->extradata,
268 ctx->par_in->extradata_size);
269 } else {
270 av_log(ctx, AV_LOG_ERROR, "Invalid extradata size: %d\n", extra_size);
271 return AVERROR_INVALIDDATA;
272 }271 }
273 272 return h264_extradata_to_annexb(ctx,
274 return 0;273 ctx->par_in->extradata,
274 ctx->par_in->extradata_size);
275}275}
276 276
277static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)277static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt)
@@ -293,10 +293,12 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) · 15 unmodified lines
293 293
294 extradata = av_packet_get_side_data(in, AV_PKT_DATA_NEW_EXTRADATA,294 extradata = av_packet_get_side_data(in, AV_PKT_DATA_NEW_EXTRADATA,
295 &extradata_size);295 &extradata_size);
296 if (extradata) {296 if (extradata && extradata[0] == 1) {
297 ret = h264_extradata_to_annexb(ctx, extradata, extradata_size);297 ret = h264_extradata_to_annexb(ctx, extradata, extradata_size);
298 if (ret < 0)298 if (ret < 0)
299 goto fail;299 goto fail;
300 av_packet_side_data_remove(in->side_data, &in->side_data_elems,
301 AV_PKT_DATA_NEW_EXTRADATA);
300 }302 }
301 303
302 /* nothing to filter */304 /* nothing to filter */
tests/fate/h264.mak+2−2
@@ -225,7 +225,7 @@ FATE_H264-$(call FRAMECRC, MOV, H264) += fate-h264-unescaped-extradata · 224 unmodified lines
225# this sample contains field-coded frames, with both fields in a single packet225# this sample contains field-coded frames, with both fields in a single packet
226FATE_H264-$(call FRAMECRC, MOV, H264) += fate-h264-twofields-packet226FATE_H264-$(call FRAMECRC, MOV, H264) += fate-h264-twofields-packet
227 227
228FATE_H264-$(call DEMMUX, MOV, H264, H264_MP4TOANNEXB_BSF SCALE_FILTER) += fate-h264-bsf-mp4toannexb-new-extradata228FATE_H264-$(call DEMMUX, MOV, H264, H264_MP4TOANNEXB_BSF H264_METADATA_BSF SCALE_FILTER) += fate-h264-bsf-mp4toannexb-new-extradata
229 229
230FATE_H264-$(call DEMMUX, MOV, H264, H264_MP4TOANNEXB_BSF) += fate-h264-bsf-mp4toannexb \230FATE_H264-$(call DEMMUX, MOV, H264, H264_MP4TOANNEXB_BSF) += fate-h264-bsf-mp4toannexb \
231 fate-h264-bsf-mp4toannexb-2 \231 fate-h264-bsf-mp4toannexb-2 \
@@ -440,7 +440,7 @@ fate-h264-bsf-mp4toannexb: CMD = md5 -i $(TARGET_SAMPLES) · 208 unmodified lines
440fate-h264-bsf-mp4toannexb-2: CMD = md5 -i $(TARGET_SAMPLES)/h264/ps_prefix_first_idr.mp4 -c:v copy -f h264440fate-h264-bsf-mp4toannexb-2: CMD = md5 -i $(TARGET_SAMPLES)/h264/ps_prefix_first_idr.mp4 -c:v copy -f h264
441fate-h264-bsf-mp4toannexb-2: CMP = oneline441fate-h264-bsf-mp4toannexb-2: CMP = oneline
442fate-h264-bsf-mp4toannexb-2: REF = cffcfa6a2d0b58c9de1f5785f099f41d442fate-h264-bsf-mp4toannexb-2: REF = cffcfa6a2d0b58c9de1f5785f099f41d
443fate-h264-bsf-mp4toannexb-new-extradata: CMD = stream_remux mov $(TARGET_SAMPLES)/h264/extradata-reload-multi-stsd.mov "" h264 "-map 0:v"443fate-h264-bsf-mp4toannexb-new-extradata: CMD = stream_remux mov $(TARGET_SAMPLES)/h264/extradata-reload-multi-stsd.mov "" h264 "-bsf h264_mp4toannexb,h264_metadata -map 0:v"
444fate-h264-bsf-dts2pts: CMD = transcode "h264" $(TARGET_SAMPLES)/h264-conformance/CAPAMA3_Sand_F.264 \444fate-h264-bsf-dts2pts: CMD = transcode "h264" $(TARGET_SAMPLES)/h264-conformance/CAPAMA3_Sand_F.264 \
445 mov "-c:v copy -bsf:v dts2pts -frames:v 50" "-c:v copy"445 mov "-c:v copy -bsf:v dts2pts -frames:v 50" "-c:v copy"
446fate-h264_mp4toannexb_ticket5927: CMD = transcode "mp4" $(TARGET_SAMPLES)/h264/thezerotheorem-cut.mp4 \446fate-h264_mp4toannexb_ticket5927: CMD = transcode "mp4" $(TARGET_SAMPLES)/h264/thezerotheorem-cut.mp4 \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t