Message ID | 20170325021329.3232-1-jamrial@gmail.com |
---|---|
State | Accepted |
Commit | d7dcd825dea3681c69a35b3147a3b42f1bf078dd |
Headers | show |
On 3/24/2017 11:13 PM, James Almer wrote: > Signed-off-by: James Almer <jamrial@gmail.com> > --- > This is an actual fix for the existing parsing code instead of a copy > of the AVCodecParser code, as an alternative to patches 2 and 3 of this > set. > > Five FATE tests will have to be updated with patch 6 if this is applied, > as this parsing code filters unnecessary NAL units and that's reflected > in the extradata size and checksum output of framecrc during codec copy. > They are: > > fate-copy-trac2211-avi > fate-h264_mp4toannexb_ticket2991 > fate-h264_mp4toannexb_ticket5927 > fate-h264_mp4toannexb_ticket5927_2 > fate-segment-mp4-to-ts > > libavcodec/extract_extradata_bsf.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) Pushed this version. Only patch 6/6 (The one that enables this functionality) remains. I'll send a new version with the above fate changes applied.
diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index d909ee6d17..af666574a3 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -65,7 +65,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, int extradata_size = 0; const int *extradata_nal_types; int nb_extradata_nal_types; - int i, ret = 0; + int i, has_sps = 0, has_vps = 0, ret = 0; if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) { extradata_nal_types = extradata_nal_types_hevc; @@ -82,11 +82,20 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, for (i = 0; i < h2645_pkt.nb_nals; i++) { H2645NAL *nal = &h2645_pkt.nals[i]; - if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) + if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) { extradata_size += nal->raw_size + 3; + if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) { + if (nal->type == HEVC_NAL_SPS) has_sps = 1; + if (nal->type == HEVC_NAL_VPS) has_vps = 1; + } else { + if (nal->type == H264_NAL_SPS) has_sps = 1; + } + } } - if (extradata_size) { + if (extradata_size && + ((ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) || + (ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) { AVBufferRef *filtered_buf; uint8_t *extradata, *filtered_data;
Signed-off-by: James Almer <jamrial@gmail.com> --- This is an actual fix for the existing parsing code instead of a copy of the AVCodecParser code, as an alternative to patches 2 and 3 of this set. Five FATE tests will have to be updated with patch 6 if this is applied, as this parsing code filters unnecessary NAL units and that's reflected in the extradata size and checksum output of framecrc during codec copy. They are: fate-copy-trac2211-avi fate-h264_mp4toannexb_ticket2991 fate-h264_mp4toannexb_ticket5927 fate-h264_mp4toannexb_ticket5927_2 fate-segment-mp4-to-ts libavcodec/extract_extradata_bsf.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)