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

Li, Zhong zhong.li at intel.com
Tue Mar 6 06:58:09 CET 2018



> -----Original Message-----
> From: libav-devel [mailto:libav-devel-bounces at libav.org] On Behalf Of Mark
> Thompson
> Sent: Tuesday, March 6, 2018 8:17 AM
> To: libav-devel at 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 <zhong.li at intel.com>
> > Committer: Luca Barbato <lu_zero at gentoo.org>
> > 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 <zhong.li at intel.com>
> > Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> >
> > ---
> >
> >  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, &q->param,
> &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/60000 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 = {0, 0, 0, 0}, reserved4 = 0, BitDepthLuma = 8,
>     BitDepthChroma = 8, Shift = 0, FrameId = {TemporalId = 0, PriorityId = 0,
> {{DependencyId = 0, QualityId = 0}, {ViewId = 0}}}, FourCC = 842094158, {{
>         Width = 7680, Height = 4320, CropX = 0, CropY = 0, CropW = 7680,
> CropH = 4320}, {BufferSize = 283123200, reserved5 = 283123200}},
> FrameRateExtN = 60,
>     FrameRateExtD = 1, reserved3 = 0, AspectRatioW = 1, AspectRatioH = 1,
> PicStruct = 1, ChromaFormat = 1, reserved2 = 0}, CodecId = 541283905,
>   CodecProfile = 0, CodecLevel = 0, NumThread = 0, {{TargetUsage = 4,
> GopPicSize = 250, GopRefDist = 4, GopOptFlag = 1, IdrInterval = 0,
>       RateControlMethod = 8, {InitialDelayInKB = 0, QPI = 0, Accuracy = 0},
> BufferSizeInKB = 0, {TargetKbps = 5000, QPP = 5000, ICQQuality = 5000}, {
>         MaxKbps = 0, QPB = 0, Convergence = 0}, NumSlice = 0,
> NumRefFrame = 0, EncodedOrder = 0}, {DecodedOrder = 4,
> ExtendedPicStruct = 250,
>       TimeStampCalc = 4, SliceGroupsPresent = 1, MaxDecFrameBuffering
> = 0, EnableReallocRequest = 8, reserved2 = {0, 0, 5000, 0, 0, 0, 0}}, {
>       JPEGChromaFormat = 4, Rotation = 250, JPEGColorFormat = 4,
> InterleavedDec = 1, SamplingFactorH = "\000\000\b", SamplingFactorV =
> "\000\000\000",
>       reserved3 = {5000, 0, 0, 0, 0}}, {Interleaved = 4, Quality = 250,
> RestartInterval = 4, reserved5 = {1, 0, 8, 0, 0, 5000, 0, 0, 0, 0}}}}
> (gdb) p param_out.mfx
> $5 = {reserved = {0, 0, 0, 0, 0, 0, 0}, LowPower = 0, BRCParamMultiplier = 1,
> FrameInfo = {reserved = {0, 0, 0, 0}, reserved4 = 0, BitDepthLuma = 0,
>     BitDepthChroma = 0, Shift = 0, FrameId = {TemporalId = 0, PriorityId = 0,
> {{DependencyId = 0, QualityId = 0}, {ViewId = 0}}}, FourCC = 842094158, {{
>         Width = 7680, Height = 4320, CropX = 0, CropY = 0, CropW = 7680,
> CropH = 4320}, {BufferSize = 283123200, reserved5 = 283123200}},
> FrameRateExtN = 16,
>     FrameRateExtD = 1, reserved3 = 0, AspectRatioW = 1, AspectRatioH = 1,
> PicStruct = 1, ChromaFormat = 1, reserved2 = 0}, CodecId = 541283905,
>   CodecProfile = 77, CodecLevel = 52, NumThread = 0, {{TargetUsage = 4,
> GopPicSize = 250, GopRefDist = 4, GopOptFlag = 1, IdrInterval = 0,
>       RateControlMethod = 0, {InitialDelayInKB = 0, QPI = 0, Accuracy = 0},
> BufferSizeInKB = 0, {TargetKbps = 34125, QPP = 34125, ICQQuality = 34125},
> {
>         MaxKbps = 0, QPB = 0, Convergence = 0}, NumSlice = 0,
> NumRefFrame = 0, EncodedOrder = 0}, {DecodedOrder = 4,
> ExtendedPicStruct = 250,
>       TimeStampCalc = 4, SliceGroupsPresent = 1, MaxDecFrameBuffering
> = 0, EnableReallocRequest = 0, reserved2 = {0, 0, 34125, 0, 0, 0, 0}}, {
>       JPEGChromaFormat = 4, Rotation = 250, JPEGColorFormat = 4,
> InterleavedDec = 1, SamplingFactorH = "\000\000\000", SamplingFactorV =
> "\000\000\000",
>       reserved3 = {34125, 0, 0, 0, 0}}, {Interleaved = 4, Quality = 250,
> RestartInterval = 4, reserved5 = {1, 0, 0, 0, 0, 34125, 0, 0, 0, 0}}}} """
> 
> (Resolutions up to 4096x4096 do work with the same command.)
> 
> I think it's probably still better than the blanket "bad rate control mode"
> message (I can get it to say the right thing for framerate, misaligned
> resolution and pixel format), but I'm not sure that it isn't going to be
> misleading in different ways in some cases like the above.
> 
> Is there something else we should be looking at to get the right message
> here?
> 
> - Mark

I believe it is a MSDK internal issue.
As the doc of MFXVideoENCODE_Query: "If the in parameter is non-zero, the function checks the validity of the fields in
the input mfxVideoParam structure. Then the function returns the corrected
values in the output mfxVideoParam structure. If there is insufficient
information to determine the validity or correction is impossible, the function
zeroes the fields." 

Looks like MSDK hasn't reset the unsupported fields here.



More information about the libav-devel mailing list