diff mbox series

[FFmpeg-devel,5/5] lavc/vaapi_encode: export encoded frame stats

Message ID 1595766367-8861-5-git-send-email-mypopydev@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/5] lavc/libkvazaar: fix framerate setting | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Jun Zhao July 26, 2020, 12:26 p.m. UTC
From: Jun Zhao <barryjzhao@tencent.com>

Export choosen pict_type.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavcodec/vaapi_encode.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Mark Thompson Aug. 8, 2020, 10:03 p.m. UTC | #1
On 26/07/2020 13:26, Jun Zhao wrote:
> From: Jun Zhao <barryjzhao@tencent.com>
> 
> Export choosen pict_type.
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>   libavcodec/vaapi_encode.c | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 6766641..2352fdd 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -24,6 +24,7 @@
>   #include "libavutil/log.h"
>   #include "libavutil/pixdesc.h"
>   
> +#include "packet_internal.h"
>   #include "vaapi_encode.h"
>   #include "encode.h"
>   #include "avcodec.h"
> @@ -633,6 +634,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
>       int total_size = 0;
>       uint8_t *ptr;
>       int err;
> +    int pict_type;
>   
>       err = vaapi_encode_wait(avctx, pic);
>       if (err < 0)
> @@ -670,6 +672,28 @@ static int vaapi_encode_output(AVCodecContext *avctx,
>   
>       pkt->pts = pic->pts;
>   
> +    switch (pic->type) {
> +    case PICTURE_TYPE_IDR:
> +    case PICTURE_TYPE_I:
> +        pict_type = AV_PICTURE_TYPE_I;
> +        break;
> +    case PICTURE_TYPE_P:
> +        pict_type = AV_PICTURE_TYPE_P;
> +        break;
> +    case PICTURE_TYPE_B:
> +        pict_type = AV_PICTURE_TYPE_B;
> +        break;
> +    default:
> +        pict_type = AV_PICTURE_TYPE_NONE;
> +        break;
> +    }

That's not right - the internal PICTURE_TYPE values here are reflecting what the frame is being used as, not what it actually is.  I think we want the latter here?

> +#if FF_API_CODED_FRAME
> +FF_DISABLE_DEPRECATION_WARNINGS
> +    avctx->coded_frame->pict_type = pict_type;
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
> +    ff_side_data_set_encoder_stats(pkt, -1, NULL, 0, pict_type);
> +
>       vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
>       if (vas != VA_STATUS_SUCCESS) {
>           av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "
> 

- Mark
diff mbox series

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6766641..2352fdd 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -24,6 +24,7 @@ 
 #include "libavutil/log.h"
 #include "libavutil/pixdesc.h"
 
+#include "packet_internal.h"
 #include "vaapi_encode.h"
 #include "encode.h"
 #include "avcodec.h"
@@ -633,6 +634,7 @@  static int vaapi_encode_output(AVCodecContext *avctx,
     int total_size = 0;
     uint8_t *ptr;
     int err;
+    int pict_type;
 
     err = vaapi_encode_wait(avctx, pic);
     if (err < 0)
@@ -670,6 +672,28 @@  static int vaapi_encode_output(AVCodecContext *avctx,
 
     pkt->pts = pic->pts;
 
+    switch (pic->type) {
+    case PICTURE_TYPE_IDR:
+    case PICTURE_TYPE_I:
+        pict_type = AV_PICTURE_TYPE_I;
+        break;
+    case PICTURE_TYPE_P:
+        pict_type = AV_PICTURE_TYPE_P;
+        break;
+    case PICTURE_TYPE_B:
+        pict_type = AV_PICTURE_TYPE_B;
+        break;
+    default:
+        pict_type = AV_PICTURE_TYPE_NONE;
+        break;
+    }
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+    avctx->coded_frame->pict_type = pict_type;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    ff_side_data_set_encoder_stats(pkt, -1, NULL, 0, pict_type);
+
     vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
     if (vas != VA_STATUS_SUCCESS) {
         av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "