[FFmpeg-devel] [PATCH] avcodec/nvenc: fix dts>pts when b frame >= 1
Timo Rothenpieler
timo at rothenpieler.org
Sat Jan 10 17:30:03 CET 2015
Am 07.01.2015 um 10:48 schrieb Agatha Hu:
> When B frames >= 1, there'll be a invalid dts/pts warning during
> encoding like:
>
> [mp4 @ 000000000034cba0] Invalid DTS: 1024 PTS: 512 in output stream
> 0:0, replacing by guess
> [mp4 @ 000000000034cba0] Invalid DTS: 1536 PTS: 1024 in output stream
> 0:0, replacing by guess
> Set a -1 offset to dts to prevent dts>pts case.
>
> From: agathah <ahu at nvidia.com>
> ---
> libavcodec/nvenc.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index 345fb78..19a3ec8 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -657,9 +657,14 @@ static av_cold int nvenc_encode_init(AVCodecContext
> *avctx)
> }
>
> if (ctx->gobpattern >= 0) {
> - ctx->encode_config.frameIntervalP = 1;
> + ctx->encode_config.frameIntervalP = ctx->gobpattern;
> }
>
> + // when there're b frames, set dts offset
> + if (ctx->encode_config.frameIntervalP >= 2) {
> + ctx->last_dts = -2;
> + }
> +
>
> ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag
> = 1;
>
> ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag
> = 1;
>
> @@ -905,6 +910,10 @@ static int process_output_surface(AVCodecContext
> *avctx, AVPacket *pkt, AVFrame
> pkt->pts = lock_params.outputTimeStamp;
> pkt->dts = timestamp_queue_dequeue(&ctx->timestamp_list);
>
> + // when there're b frame(s), set dts offset
> + if (ctx->encode_config.frameIntervalP >= 2)
> + pkt->dts -= 1;
> +
> if (pkt->dts > pkt->pts)
> pkt->dts = pkt->pts;
>
Looks good to merge for me.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150110/8a6a2396/attachment.asc>
More information about the ffmpeg-devel
mailing list