---
There was a previous version of this; the logic of this one is the same but
slightly cleaner because of the preceding patch.
libavcodec/vaapi_encode.c | 18 ++++++++++++++----
libavcodec/vaapi_encode.h | 1 +
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index c670ae62d..246b76abc 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -605,6 +605,7 @@ static int vaapi_encode_step(AVCodecContext *avctx,
if (err < 0)
return err;
activity = 1;
+ break;
}
} while(activity);
@@ -639,8 +640,10 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
if (!pic)
return AVERROR(ENOMEM);
- if (ctx->input_order == 0 || ctx->gop_counter >= avctx->gop_size) {
+ if (ctx->input_order == 0 || ctx->force_idr ||
+ ctx->gop_counter >= avctx->gop_size) {
pic->type = PICTURE_TYPE_IDR;
+ ctx->force_idr = 0;
ctx->gop_counter = 1;
ctx->p_counter = 0;
} else if (ctx->p_counter >= ctx->p_per_i) {
@@ -722,7 +725,7 @@ fail:
return AVERROR(ENOMEM);
}
-static int vaapi_encode_mangle_end(AVCodecContext *avctx)
+static int vaapi_encode_truncate_gop(AVCodecContext *avctx)
{
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodePicture *pic, *last_pic, *next;
@@ -772,7 +775,7 @@ static int vaapi_encode_mangle_end(AVCodecContext *avctx)
// mangle anything.
}
- av_log(avctx, AV_LOG_DEBUG, "Pictures at end of stream:");
+ av_log(avctx, AV_LOG_DEBUG, "Pictures ending truncated GOP:");
for (pic = ctx->pic_start; pic; pic = pic->next) {
av_log(avctx, AV_LOG_DEBUG, " %s (%"PRId64"/%"PRId64")",
picture_type_name[pic->type],
@@ -826,6 +829,13 @@ int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
av_log(avctx, AV_LOG_DEBUG, "Encode frame: %ux%u (%"PRId64").\n",
input_image->width, input_image->height, input_image->pts);
+ if (input_image->pict_type == AV_PICTURE_TYPE_I) {
+ err = vaapi_encode_truncate_gop(avctx);
+ if (err < 0)
+ goto fail;
+ ctx->force_idr = 1;
+ }
+
err = vaapi_encode_get_next(avctx, &pic);
if (err) {
av_log(avctx, AV_LOG_ERROR, "Input setup failed: %d.\n", err);
@@ -854,7 +864,7 @@ int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
} else {
if (!ctx->end_of_stream) {
- err = vaapi_encode_mangle_end(avctx);
+ err = vaapi_encode_truncate_gop(avctx);
if (err < 0)
goto fail;
ctx->end_of_stream = 1;
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index e8ed4fdb4..2a72510b8 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -192,6 +192,7 @@ typedef struct VAAPIEncodeContext {
// Frame type decision.
int p_per_i;
int b_per_p;
+ int force_idr;
int gop_counter;
int p_counter;
int end_of_stream;
--
2.11.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel