[FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

Fu, Linjie linjie.fu at intel.com
Tue Nov 13 03:30:12 EET 2018


> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces at ffmpeg.org] On Behalf
> Of Mark Thompson
> Sent: Sunday, November 11, 2018 23:09
> To: ffmpeg-devel at ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3] fftools/ffmpeg: add an option to
> forbid the fallback to software path when hardware init fails
> 
> On 09/11/18 09:05, Linjie Fu wrote:
> > Currently ff_get_format will go through all usable choices if the chosen
> > format was not supported. It will fallback to software path if the hardware
> > init fails.
> >
> > Provided an option "-require_hwaccel 1" in user-code to detect frame-
> >format and
> > hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.
> >
> > Signed-off-by: Linjie Fu <linjie.fu at intel.com>
> > ---
> > [v2] detect hardware init failures in get_buffer and modify in user-code
> > [v3] changed the option name, add error message
> >
> >  fftools/ffmpeg.c     | 4 ++++
> >  fftools/ffmpeg.h     | 3 +++
> >  fftools/ffmpeg_opt.c | 4 ++++
> >  3 files changed, 11 insertions(+)
> >
> > diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> > index da4259a9a8..113ab6312a 100644
> > --- a/fftools/ffmpeg.c
> > +++ b/fftools/ffmpeg.c
> > @@ -2890,6 +2890,10 @@ static int get_buffer(AVCodecContext *s,
> AVFrame *frame, int flags)
> >
> >      if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)
> >          return ist->hwaccel_get_buffer(s, frame, flags);
> > +    else if (ist->require_hwaccel) {
> > +        av_log(s, AV_LOG_ERROR, "Hardware acceleration is required and will
> not fallback to try software path.\n");
> > +        return AVERROR(EINVAL);
> > +    }
> 
> Um, doesn't this just break every hardware case except QSV?  The
> hwaccel_get_buffer function is only used for QSV, and will be unset for any
> other cases.  (In fact, I don't think it does anything useful there anyway -
> maybe it can be removed completely, I'll have a look.)
> 
> I think the right place to make this decision (to force a hardware format) is in
> get_format(), rather than after when the decoder is already configured - this
> avoids cases where the format you actually wanted was available but you
> didn't pick it and then fail later.  I had a patch lying around for another
> purpose which gives you some support for this, just sent if you'd like to have
> a look.
> 
Thanks for the comments and hints.


More information about the ffmpeg-devel mailing list