Message ID | 20180815063738.27192-1-linjie.fu@intel.com |
---|---|
State | Superseded |
Headers | show |
On Wed, Aug 15, 2018 at 2:38 PM Linjie Fu <linjie.fu@intel.com> wrote: > > Fix the live stream encoding problem using qsv when the first frame > is not an IDR frame. > > Add the extradata information when the IDR frame is missing in the > first GOP. > > Fixes the bug reported in ticket #6418. > > Signed-off-by: Linjie Fu <linjie.fu@intel.com> > --- > libavcodec/h264_mp4toannexb_bsf.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c > index 794c82e650..fbbfe3f7dd 100644 > --- a/libavcodec/h264_mp4toannexb_bsf.c > +++ b/libavcodec/h264_mp4toannexb_bsf.c > @@ -33,6 +33,7 @@ typedef struct H264BSFContext { > int32_t pps_offset; > uint8_t length_size; > uint8_t new_idr; > + uint8_t new_nal_slice; > uint8_t idr_sps_seen; > uint8_t idr_pps_seen; > int extradata_parsed; > @@ -243,6 +244,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) > buf, nal_size, 1)) < 0) > goto fail; > s->new_idr = 0; > + s->new_nal_slice = 1; > /* if only SPS has been seen, also insert PPS */ > } else if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && s->idr_sps_seen && !s->idr_pps_seen) { > if (s->pps_offset == -1) { > @@ -253,7 +255,16 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) > ctx->par_out->extradata + s->pps_offset, ctx->par_out->extradata_size - s->pps_offset, > buf, nal_size, 1)) < 0) > goto fail; > - } else { > + }else if (s->new_idr && !s->new_nal_slice && H264_NAL_SLICE == unit_type && !s->idr_sps_seen && !s->idr_pps_seen) > + { > + av_log(ctx, AV_LOG_WARNING, "first H264_NAL_SLICE when there is no IDR.\n"); > + if ((ret = alloc_and_copy(out, ctx->par_out->extradata, ctx->par_out->extradata_size, buf, nal_size, 1)) < 0) > + goto fail; > + s->new_nal_slice = 1; > + s->new_idr = 0; > + } > + > + else { > if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size, unit_type == H264_NAL_SPS || unit_type == H264_NAL_PPS)) < 0) > goto fail; > if (!s->new_idr && unit_type == H264_NAL_SLICE) { > -- Need to follow FFmpeg coding style, I think, more information, you can refer to the link: https://www.ffmpeg.org/developer.html. Thanks.
diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 794c82e650..fbbfe3f7dd 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -33,6 +33,7 @@ typedef struct H264BSFContext { int32_t pps_offset; uint8_t length_size; uint8_t new_idr; + uint8_t new_nal_slice; uint8_t idr_sps_seen; uint8_t idr_pps_seen; int extradata_parsed; @@ -243,6 +244,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) buf, nal_size, 1)) < 0) goto fail; s->new_idr = 0; + s->new_nal_slice = 1; /* if only SPS has been seen, also insert PPS */ } else if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && s->idr_sps_seen && !s->idr_pps_seen) { if (s->pps_offset == -1) { @@ -253,7 +255,16 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) ctx->par_out->extradata + s->pps_offset, ctx->par_out->extradata_size - s->pps_offset, buf, nal_size, 1)) < 0) goto fail; - } else { + }else if (s->new_idr && !s->new_nal_slice && H264_NAL_SLICE == unit_type && !s->idr_sps_seen && !s->idr_pps_seen) + { + av_log(ctx, AV_LOG_WARNING, "first H264_NAL_SLICE when there is no IDR.\n"); + if ((ret = alloc_and_copy(out, ctx->par_out->extradata, ctx->par_out->extradata_size, buf, nal_size, 1)) < 0) + goto fail; + s->new_nal_slice = 1; + s->new_idr = 0; + } + + else { if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size, unit_type == H264_NAL_SPS || unit_type == H264_NAL_PPS)) < 0) goto fail; if (!s->new_idr && unit_type == H264_NAL_SLICE) {
Fix the live stream encoding problem using qsv when the first frame is not an IDR frame. Add the extradata information when the IDR frame is missing in the first GOP. Fixes the bug reported in ticket #6418. Signed-off-by: Linjie Fu <linjie.fu@intel.com> --- libavcodec/h264_mp4toannexb_bsf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)