[FFmpeg-devel,v4,7/7] vaapi_encode: Warn if input has cropping information

Submitted by Mark Thompson on April 9, 2019, 10:07 p.m.

Details

Message ID 20190409220730.29311-7-sw@jkqxz.net
State Accepted
Commit 909bcedc581aa03dd5e22ecb1d0cc3b52eba8c26
Headers show

Commit Message

Mark Thompson April 9, 2019, 10:07 p.m.
Cropping is not supported by VAAPI encode.
---
On 26/03/2019 10:59, Song, Ruiling wrote:> 
> And do we need to add warning message against crop information in encoder if user failed to add some vaapi filter after crop?
> Seems that vaapi encoder does not encode correctly with crop?

That's a good idea :)


 libavcodec/vaapi_encode.c | 19 +++++++++++++++++++
 libavcodec/vaapi_encode.h |  4 ++++
 2 files changed, 23 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2dda451882..c3d8944c3c 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -913,6 +913,21 @@  static int vaapi_encode_clear_old(AVCodecContext *avctx)
     return 0;
 }
 
+static int vaapi_encode_check_frame(AVCodecContext *avctx,
+                                    const AVFrame *frame)
+{
+    VAAPIEncodeContext *ctx = avctx->priv_data;
+
+    if ((frame->crop_top  || frame->crop_bottom ||
+         frame->crop_left || frame->crop_right) && !ctx->crop_warned) {
+        av_log(avctx, AV_LOG_WARNING, "Cropping information on input "
+               "frames ignored due to lack of API support.\n");
+        ctx->crop_warned = 1;
+    }
+
+    return 0;
+}
+
 int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame)
 {
     VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -923,6 +938,10 @@  int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame)
         av_log(avctx, AV_LOG_DEBUG, "Input frame: %ux%u (%"PRId64").\n",
                frame->width, frame->height, frame->pts);
 
+        err = vaapi_encode_check_frame(avctx, frame);
+        if (err < 0)
+            return err;
+
         pic = vaapi_encode_alloc(avctx);
         if (!pic)
             return AVERROR(ENOMEM);
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 44a8db566e..12efee2d08 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -314,6 +314,10 @@  typedef struct VAAPIEncodeContext {
     int idr_counter;
     int gop_counter;
     int end_of_stream;
+
+    // The encoder does not support cropping information, so warn about
+    // it the first time we encounter any nonzero crop fields.
+    int             crop_warned;
 } VAAPIEncodeContext;
 
 enum {