Re: [libav-devel] [libav-commits] qsvenc: Provide a detailed error message if the parameters are invalid

2018-03-05 Thread Li, Zhong


> -Original Message-
> From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of Mark
> Thompson
> Sent: Tuesday, March 6, 2018 8:17 AM
> To: libav-devel@libav.org
> Subject: Re: [libav-devel] [libav-commits] qsvenc: Provide a detailed error
> message if the parameters are invalid
> 
> On 05/03/18 09:40, Zhong Li  wrote:
> > Module: libav
> > Branch: master
> > Commit: 2d6b3f3a9dce409ca51d70ef4b85c0593bb4b109
> >
> > Author:Zhong Li 
> > Committer: Luca Barbato 
> > Date:  Fri Mar  2 11:26:27 2018 +0800
> >
> > qsvenc: Provide a detailed error message if the parameters are invalid
> >
> > Currently it always shows "Selected ratecontrol mode is not supported
> > by the QSV runtime. Choose a different mode", but sometimes it is not
> > accurate.
> >
> > Signed-off-by: Zhong Li 
> > Signed-off-by: Luca Barbato 
> >
> > ---
> >
> >  libavcodec/qsvenc.c | 31 +--
> >  1 file changed, 25 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
> > 16d942f..d4dd4a3 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -356,15 +356,34 @@ static int select_rc_mode(AVCodecContext
> *avctx, QSVEncContext *q)
> >  return 0;
> >  }
> >
> > -static int rc_supported(QSVEncContext *q)
> > +static int check_enc_param(AVCodecContext *avctx, QSVEncContext *q)
> >  {
> >  mfxVideoParam param_out = { .mfx.CodecId =
> q->param.mfx.CodecId };
> >  mfxStatus ret;
> >
> > +#define UNMATCH(x) (param_out.mfx.x != q->param.mfx.x)
> > +
> >  ret = MFXVideoENCODE_Query(q->session, >param,
> _out);
> > -if (ret < 0 ||
> > -param_out.mfx.RateControlMethod !=
> q->param.mfx.RateControlMethod)
> > +
> > +if (ret < 0) {
> > +if (UNMATCH(CodecId))
> > +av_log(avctx, AV_LOG_ERROR, "Current codec type is
> unsupported\n");
> > +if (UNMATCH(CodecProfile))
> > +av_log(avctx, AV_LOG_ERROR, "Current profile is
> unsupported\n");
> > +if (UNMATCH(RateControlMethod))
> > +av_log(avctx, AV_LOG_ERROR, "Selected ratecontrol
> mode is unsupported\n");
> > +if (UNMATCH(LowPower))
> > +  av_log(avctx, AV_LOG_ERROR, "Low power mode is
> unsupported\n");
> > +if (UNMATCH(FrameInfo.FrameRateExtN) ||
> UNMATCH(FrameInfo.FrameRateExtN))
> > +  av_log(avctx, AV_LOG_ERROR, "Current frame rate is
> unsupported\n");
> > +if (UNMATCH(FrameInfo.PicStruct))
> > +  av_log(avctx, AV_LOG_ERROR, "Current picture
> structure is unsupported\n");
> > +if (UNMATCH(FrameInfo.Width) ||
> UNMATCH(FrameInfo.Height))
> > +  av_log(avctx, AV_LOG_ERROR, "Current resolution is
> unsupported\n");
> > +if (UNMATCH(FrameInfo.FourCC))
> > +  av_log(avctx, AV_LOG_ERROR, "Current pixel format is
> > + unsupported\n");
> >  return 0;
> > +}
> >  return 1;
> >  }
> >
> > @@ -639,10 +658,10 @@ FF_ENABLE_DEPRECATION_WARNINGS  #endif
> >  }
> >
> > -if (!rc_supported(q)) {
> > +if (!check_enc_param(avctx,q)) {
> >  av_log(avctx, AV_LOG_ERROR,
> > -   "Selected ratecontrol mode is not supported by the QSV
> "
> > -   "runtime. Choose a different mode.\n");
> > +   "some encoding parameters are not supported by the
> QSV "
> > +   "runtime. Please double check the input
> > + parameters.\n");
> >  return AVERROR(ENOSYS);
> >  }
> >
> 
> Testing this a bit, I'm not entirely sure that it's acting in the expected 
> way.
> For example:
> 
> """
> $ LIBVA_DRIVER_NAME=iHD
> LIBVA_DRIVERS_PATH=/opt/intel/mediasdk/lib64/ DISPLAY= ./avconv -v 55
> -y -i bbb_1080_264.mp4 -an -vf 'scale=7680:4320' -c:v h264_qsv -b:v 5M
> -la_depth 50 -frames:v 1000 out.mp4 avconv version
> v13_dev0-1487-g2d6b3f3, Copyright (c) 2000-2018 the Libav developers ...
> [buffer @ 0x375eca0] w:1920 h:1080 pixfmt:yuv420p tb:1/6 sar:1/1
> [fps @ 0x3aac380] fps=60/1 [buffersink @ 0x37c79e0] auto-inserting filter
> 'auto-inserted fifo 0' between the filter 'fps for output stream 0:0' and the
> filter 'output stream 0:0'
> [scale @ 0x3ab0300] w:1920 h:1080 fmt:yuv420p -> w:7680 h:4320
> fmt:nv12 flags:0x4 [h264_qsv @ 0x381e660] Initialized an internal MFX
> session using hardware accelerated implementation [h264_qsv @
> 0x381e660] Using the VBR with lookahead (LA) ratecontrol method libva info:
> VA-API version 0.99.0 libva info: va_getDriverName() returns 0 libva info:
> User requested driver 'iHD'
> libva info: Trying to open /opt/intel/mediasdk/lib64//iHD_drv_video.so
> libva info: Found init function __vaDriverInit_0_32 libva info: 
> va_openDriver()
> returns 0 [h264_qsv @ 0x381e660] Current profile is unsupported [h264_qsv
> @ 0x381e660] Selected ratecontrol mode is unsupported [h264_qsv @
> 0x381e660] Current frame rate is unsupported [h264_qsv 

[libav-devel] [PATCH] qsv: align surface width/height to 16.

2018-03-05 Thread Ruiling Song
Per MediaSDK documentation, it requires width/height to 16 alignment.
Without this patch, hwupload pipeline may fail if 16 alignment is
not met. Although this patch also apply 16 alignment to qsv encoder/decoder,
it will not bring any side-effect to them as they are already aligned.

Signed-off-by: Ruiling Song 
---
 libavutil/hwcontext_qsv.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 73b5f24..f5d78d0 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -234,8 +234,8 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx)
 child_frames_ctx->format= device_priv->child_pix_fmt;
 child_frames_ctx->sw_format = ctx->sw_format;
 child_frames_ctx->initial_pool_size = ctx->initial_pool_size;
-child_frames_ctx->width = ctx->width;
-child_frames_ctx->height= ctx->height;
+child_frames_ctx->width = FFALIGN(ctx->width, 16);
+child_frames_ctx->height= FFALIGN(ctx->height, 16);
 
 #if CONFIG_DXVA2
 if (child_device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
@@ -307,9 +307,9 @@ static int qsv_init_surface(AVHWFramesContext *ctx, 
mfxFrameSurface1 *surf)
 surf->Info.ChromaFormat   = MFX_CHROMAFORMAT_YUV444;
 
 surf->Info.FourCC = fourcc;
-surf->Info.Width  = ctx->width;
+surf->Info.Width  = FFALIGN(ctx->width, 16);
 surf->Info.CropW  = ctx->width;
-surf->Info.Height = ctx->height;
+surf->Info.Height = FFALIGN(ctx->height, 16);
 surf->Info.CropH  = ctx->height;
 surf->Info.FrameRateExtN  = 25;
 surf->Info.FrameRateExtD  = 1;
-- 
2.7.4

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [libav-commits] qsvenc: Provide a detailed error message if the parameters are invalid

2018-03-05 Thread Mark Thompson
On 05/03/18 09:40, Zhong Li  wrote:
> Module: libav
> Branch: master
> Commit: 2d6b3f3a9dce409ca51d70ef4b85c0593bb4b109
> 
> Author:Zhong Li 
> Committer: Luca Barbato 
> Date:  Fri Mar  2 11:26:27 2018 +0800
> 
> qsvenc: Provide a detailed error message if the parameters are invalid
> 
> Currently it always shows "Selected ratecontrol mode is not supported
> by the QSV runtime. Choose a different mode", but sometimes it is not
> accurate.
> 
> Signed-off-by: Zhong Li 
> Signed-off-by: Luca Barbato 
> 
> ---
> 
>  libavcodec/qsvenc.c | 31 +--
>  1 file changed, 25 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 16d942f..d4dd4a3 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -356,15 +356,34 @@ static int select_rc_mode(AVCodecContext *avctx, 
> QSVEncContext *q)
>  return 0;
>  }
>  
> -static int rc_supported(QSVEncContext *q)
> +static int check_enc_param(AVCodecContext *avctx, QSVEncContext *q)
>  {
>  mfxVideoParam param_out = { .mfx.CodecId = q->param.mfx.CodecId };
>  mfxStatus ret;
>  
> +#define UNMATCH(x) (param_out.mfx.x != q->param.mfx.x)
> +
>  ret = MFXVideoENCODE_Query(q->session, >param, _out);
> -if (ret < 0 ||
> -param_out.mfx.RateControlMethod != q->param.mfx.RateControlMethod)
> +
> +if (ret < 0) {
> +if (UNMATCH(CodecId))
> +av_log(avctx, AV_LOG_ERROR, "Current codec type is 
> unsupported\n");
> +if (UNMATCH(CodecProfile))
> +av_log(avctx, AV_LOG_ERROR, "Current profile is unsupported\n");
> +if (UNMATCH(RateControlMethod))
> +av_log(avctx, AV_LOG_ERROR, "Selected ratecontrol mode is 
> unsupported\n");
> +if (UNMATCH(LowPower))
> +  av_log(avctx, AV_LOG_ERROR, "Low power mode is unsupported\n");
> +if (UNMATCH(FrameInfo.FrameRateExtN) || 
> UNMATCH(FrameInfo.FrameRateExtN))
> +  av_log(avctx, AV_LOG_ERROR, "Current frame rate is 
> unsupported\n");
> +if (UNMATCH(FrameInfo.PicStruct))
> +  av_log(avctx, AV_LOG_ERROR, "Current picture structure is 
> unsupported\n");
> +if (UNMATCH(FrameInfo.Width) || UNMATCH(FrameInfo.Height))
> +  av_log(avctx, AV_LOG_ERROR, "Current resolution is 
> unsupported\n");
> +if (UNMATCH(FrameInfo.FourCC))
> +  av_log(avctx, AV_LOG_ERROR, "Current pixel format is 
> unsupported\n");
>  return 0;
> +}
>  return 1;
>  }
>  
> @@ -639,10 +658,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  #endif
>  }
>  
> -if (!rc_supported(q)) {
> +if (!check_enc_param(avctx,q)) {
>  av_log(avctx, AV_LOG_ERROR,
> -   "Selected ratecontrol mode is not supported by the QSV "
> -   "runtime. Choose a different mode.\n");
> +   "some encoding parameters are not supported by the QSV "
> +   "runtime. Please double check the input parameters.\n");
>  return AVERROR(ENOSYS);
>  }
>  

Testing this a bit, I'm not entirely sure that it's acting in the expected way. 
 For example:

"""
$ LIBVA_DRIVER_NAME=iHD LIBVA_DRIVERS_PATH=/opt/intel/mediasdk/lib64/ DISPLAY= 
./avconv -v 55 -y -i bbb_1080_264.mp4 -an -vf 'scale=7680:4320' -c:v h264_qsv 
-b:v 5M -la_depth 50 -frames:v 1000 out.mp4
avconv version v13_dev0-1487-g2d6b3f3, Copyright (c) 2000-2018 the Libav 
developers
...
[buffer @ 0x375eca0] w:1920 h:1080 pixfmt:yuv420p tb:1/6 sar:1/1
[fps @ 0x3aac380] fps=60/1
[buffersink @ 0x37c79e0] auto-inserting filter 'auto-inserted fifo 0' between 
the filter 'fps for output stream 0:0' and the filter 'output stream 0:0'
[scale @ 0x3ab0300] w:1920 h:1080 fmt:yuv420p -> w:7680 h:4320 fmt:nv12 
flags:0x4
[h264_qsv @ 0x381e660] Initialized an internal MFX session using hardware 
accelerated implementation
[h264_qsv @ 0x381e660] Using the VBR with lookahead (LA) ratecontrol method
libva info: VA-API version 0.99.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64//iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32
libva info: va_openDriver() returns 0
[h264_qsv @ 0x381e660] Current profile is unsupported
[h264_qsv @ 0x381e660] Selected ratecontrol mode is unsupported
[h264_qsv @ 0x381e660] Current frame rate is unsupported
[h264_qsv @ 0x381e660] some encoding parameters are not supported by the QSV 
runtime. Please double check the input parameters.
Error initializing output stream 0:0 -- Error while opening encoder for output 
stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
"""

I was hoping for "resolution is unsupported" there, but that's one thing which 
it didn't reject:

"""
(gdb) p q->param.mfx
$4 = {reserved = {0, 0, 0, 0, 0, 0, 0}, LowPower = 0, BRCParamMultiplier = 0, 
FrameInfo = {reserved