Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2019-05-01 Thread Eoff, Ullysses A
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Carl 
> Eugen Hoyos
> Sent: Wednesday, May 01, 2019 2:59 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific 
> decode format
> 
> 2019-04-30 19:48 GMT+02:00, Eoff, Ullysses A :
> >> -Original Message-
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> >> Carl Eugen Hoyos
> >> Sent: Tuesday, April 23, 2019 12:48 PM
> >> To: FFmpeg development discussions and patches 
> >> Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific
> >> decode format
> >>
> >> 2018-11-11 15:54 GMT+01:00, Mark Thompson :
> >> > Fixes #7519.
> >>
> >> > +{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT
> >> > |
> >> > +OPT_SPEC | OPT_INPUT,
> >> >  { .off = OFFSET(decode_formats) },
> >> > +"set output format used by decoder, fail if this format is not
> >> > available", "format" },
> >>
> >> Sorry if this was already asked:
> >> Why can't you use the input option "pix_fmt"?
> >
> > Are you saying that pix_fmt is already supported as in input option
> 
> I assume the reason that you sent the patch is that this is not
> the case.
> 
> > for decode or, instead, that this patch should enable pix_fmt to be
> > used as such instead of adding a new option name?
> 
> I believe this would make user's life easier, yes.
> 

I agree.  Mark, can you update your patch?

> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2019-05-01 Thread Dennis Mungai
On Wed, 1 May 2019 at 13:04, Carl Eugen Hoyos  wrote:

> 2019-04-30 19:48 GMT+02:00, Eoff, Ullysses A :
> >> -Original Message-
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of
> >> Carl Eugen Hoyos
> >> Sent: Tuesday, April 23, 2019 12:48 PM
> >> To: FFmpeg development discussions and patches  >
> >> Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a
> specific
> >> decode format
> >>
> >> 2018-11-11 15:54 GMT+01:00, Mark Thompson :
> >> > Fixes #7519.
> >>
> >> > +{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT
> >> > |
> >> > +OPT_SPEC | OPT_INPUT,
> >> >  { .off = OFFSET(decode_formats) },
> >> > +"set output format used by decoder, fail if this format is
> not
> >> > available", "format" },
> >>
> >> Sorry if this was already asked:
> >> Why can't you use the input option "pix_fmt"?
> >
> > Are you saying that pix_fmt is already supported as in input option
>
> I assume the reason that you sent the patch is that this is not
> the case.
>
> > for decode or, instead, that this patch should enable pix_fmt to be
> > used as such instead of adding a new option name?
>
> I believe this would make user's life easier, yes.
>
> Carl Eugen
>
>
A case in point: Testing with *some* input files, such as this:

ffprobe -i rv.mkvffprobe -i rv.mkv
ffprobe version N-93719-g19af948e53 Copyright (c) 2007-2019 the FFmpeg
developers
  built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04)
  configuration: --pkg-config-flags=--static --prefix=/home/brainiarc7/bin
--bindir=/home/brainiarc7/bin --extra-cflags=-I/home/brainiarc7/bin/include
--extra-ldflags=-L/home/brainiarc7/bin/lib --enable-cuda-nvcc
--enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include/
--extra-ldflags=-L/usr/local/cuda/lib64/ --enable-nvenc
--extra-cflags=-I/opt/intel/mediasdk/include
--extra-ldflags=-L/opt/intel/mediasdk/lib
--extra-ldflags=-L/opt/intel/mediasdk/plugins --enable-libmfx
--enable-libass --enable-vaapi --disable-debug --enable-libvorbis
--enable-libvpx --enable-libdrm --enable-opencl --enable-gpl --cpu=native
--enable-opengl --enable-libfdk-aac --enable-libx265 --enable-openssl
--extra-libs='-lpthread -lm -lz' --enable-nonfree
  libavutil  56. 26.100 / 56. 26.100
  libavcodec 58. 52.100 / 58. 52.100
  libavformat58. 27.103 / 58. 27.103
  libavdevice58.  7.100 / 58.  7.100
  libavfilter 7. 50.100 /  7. 50.100
  libswscale  5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc55.  4.100 / 55.  4.100
Input #0, matroska,webm, from 'rv.mkv':
  Metadata:
ENCODER : Lavf58.27.102
  Duration: 00:02:24.77, start: 0.00, bitrate: 20063 kb/s
Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p(progressive),
2560x1440, 60 fps, 60 tbr, 1k tbn, 120 tbc (default)
Metadata:
  ENCODER : Lavc58.51.100 libx264
  DURATION: 00:02:24.76700

With VAAPI, with either driver, i915 or iHD results in failure:

1. with i915:

LIBVA_DRIVER_NAME=i965 ffmpeg -y -stats \
-init_hw_device vaapi=va:/dev/dri/renderD128 -filter_hw_device va -hwaccel
vaapi \
-i 'rv.mkv' -vf 'hwupload,format=vaapi|nv12'  \
-c:v h264_vaapi -bf:v 3 -rc_mode:v 3 -coder:v cabac -profile:v main  \
-b:v 7.5M -maxrate:v 15M -bufsize:v 0.5M -r:v 60 -an -f mpegts -y /dev/null

ffmpeg version N-93719-g19af948e53 Copyright (c) 2000-2019 the FFmpeg
developers
  built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04)
  configuration: --pkg-config-flags=--static --prefix=/home/brainiarc7/bin
--bindir=/home/brainiarc7/bin --extra-cflags=-I/home/brainiarc7/bin/include
--extra-ldflags=-L/home/brainiarc7/bin/lib --enable-cuda-nvcc
--enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include/
--extra-ldflags=-L/usr/local/cuda/lib64/ --enable-nvenc
--extra-cflags=-I/opt/intel/mediasdk/include
--extra-ldflags=-L/opt/intel/mediasdk/lib
--extra-ldflags=-L/opt/intel/mediasdk/plugins --enable-libmfx
--enable-libass --enable-vaapi --disable-debug --enable-libvorbis
--enable-libvpx --enable-libdrm --enable-opencl --enable-gpl --cpu=native
--enable-opengl --enable-libfdk-aac --enable-libx265 --enable-openssl
--extra-libs='-lpthread -lm -lz' --enable-nonfree
  libavutil  56. 26.100 / 56. 26.100
  libavcodec 58. 52.100 / 58. 52.100
  libavformat58. 27.103 / 58. 27.103
  libavdevice58.  7.100 / 58.  7.100
  libavfilter 7. 50.100 /  7. 50.100
  libswscale  5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc55.  4.100 / 55.  4.100
Input #0, matroska,webm, from 'rv.mkv':
  Metadata:
ENCODER : Lavf58.27.102
  Duration: 00:02:24.77, st

Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2019-05-01 Thread Carl Eugen Hoyos
2019-04-30 19:48 GMT+02:00, Eoff, Ullysses A :
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
>> Carl Eugen Hoyos
>> Sent: Tuesday, April 23, 2019 12:48 PM
>> To: FFmpeg development discussions and patches 
>> Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific
>> decode format
>>
>> 2018-11-11 15:54 GMT+01:00, Mark Thompson :
>> > Fixes #7519.
>>
>> > +{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT
>> > |
>> > +OPT_SPEC | OPT_INPUT,
>> >  { .off = OFFSET(decode_formats) },
>> > +"set output format used by decoder, fail if this format is not
>> > available", "format" },
>>
>> Sorry if this was already asked:
>> Why can't you use the input option "pix_fmt"?
>
> Are you saying that pix_fmt is already supported as in input option

I assume the reason that you sent the patch is that this is not
the case.

> for decode or, instead, that this patch should enable pix_fmt to be
> used as such instead of adding a new option name?

I believe this would make user's life easier, yes.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2019-04-30 Thread Eoff, Ullysses A
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Carl 
> Eugen Hoyos
> Sent: Tuesday, April 23, 2019 12:48 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific 
> decode format
> 
> 2018-11-11 15:54 GMT+01:00, Mark Thompson :
> > Fixes #7519.
> 
> > +{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
> > +OPT_SPEC | OPT_INPUT,
> >  { .off = OFFSET(decode_formats) },
> > +"set output format used by decoder, fail if this format is not
> > available", "format" },
> 
> Sorry if this was already asked:
> Why can't you use the input option "pix_fmt"?
> 

Are you saying that pix_fmt is already supported as in input option
for decode or, instead, that this patch should enable pix_fmt to be
used as such instead of adding a new option name?

> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2019-04-23 Thread Carl Eugen Hoyos
2018-11-11 15:54 GMT+01:00, Mark Thompson :
> Fixes #7519.

> +{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
> +OPT_SPEC | OPT_INPUT,
>  { .off = OFFSET(decode_formats) },
> +"set output format used by decoder, fail if this format is not
> available", "format" },

Sorry if this was already asked:
Why can't you use the input option "pix_fmt"?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2018-11-13 Thread Mark Thompson
On 12/11/18 20:20, Michael Niedermayer wrote:
> On Sun, Nov 11, 2018 at 02:54:41PM +, Mark Thompson wrote:
>> Fixes #7519.
>> ---
>> I've had this lying around for a bit with intent to use it to support 
>> non-hwaccel hardware decoders (in particular, v4l2m2m), but it actually 
>> fixes the force-hwaccel use-case too in a sensible way.
>>
>>
>>  doc/ffmpeg.texi  | 12 
>>  fftools/ffmpeg.c |  4 
>>  fftools/ffmpeg.h |  4 
>>  fftools/ffmpeg_opt.c | 15 +++
>>  4 files changed, 35 insertions(+)
>>
>> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
>> index 3717f22d42..9f9e693898 100644
>> --- a/doc/ffmpeg.texi
>> +++ b/doc/ffmpeg.texi
>> @@ -920,6 +920,18 @@ would be more efficient.
>>  When doing stream copy, copy also non-key frames found at the
>>  beginning.
>>  
>> +@item -decode_format[:@var{stream_specifier}] @var{pixfmt} 
>> (@emph{input,per-stream})
>> +Set the output format to be used by the decoder for this stream.  If the
>> +decoder does not natively support this format for the input stream then
>> +decoding will fail rather than continuing with a different format.
>> +
>> +In general this should not be set - the decoder will select an output
>> +format based on the input stream parameters and available components, and
>> +that will be automatically converted to whatever the output requires.  It
>> +may be useful to force a hardware decoder supporting output in multiple
>> +different memory types to pick the desired one, or to ensure that a
>> +hardware decoder is used when software fallback is also available.
>> +
>>  @item -init_hw_device 
>> @var{type}[=@var{name}][:@var{device}[,@var{key=value}...]]
>>  Initialise a new hardware device of type @var{type} called @var{name}, 
>> using the
>>  given device parameters.
>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
>> index 38c21e944a..73bed55e4d 100644
>> --- a/fftools/ffmpeg.c
>> +++ b/fftools/ffmpeg.c
>> @@ -2800,6 +2800,10 @@ static enum AVPixelFormat get_format(AVCodecContext 
>> *s, const enum AVPixelFormat
>>  const AVCodecHWConfig  *config = NULL;
>>  int i;
>>  
>> +if (ist->decode_format != AV_PIX_FMT_NONE &&
>> +ist->decode_format != *p)
>> +continue;
>> +
>>  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
>>  break;
>>  
>> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
>> index eb1eaf6363..88e0aa60ea 100644
>> --- a/fftools/ffmpeg.h
>> +++ b/fftools/ffmpeg.h
>> @@ -125,6 +125,8 @@ typedef struct OptionsContext {
>>  intnb_ts_scale;
>>  SpecifierOpt *dump_attachment;
>>  intnb_dump_attachment;
>> +SpecifierOpt *decode_formats;
>> +intnb_decode_formats;
>>  SpecifierOpt *hwaccels;
>>  intnb_hwaccels;
>>  SpecifierOpt *hwaccel_devices;
> 
>> @@ -334,6 +336,8 @@ typedef struct InputStream {
>>  int top_field_first;
>>  int guess_layout_max;
>>  
>> +enum AVPixelFormat decode_format;
>> +
> 
> I think this should be a list and not a single format

Yes, I agree; that's a very good idea.

New patch to follow.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2018-11-12 Thread Michael Niedermayer
On Sun, Nov 11, 2018 at 02:54:41PM +, Mark Thompson wrote:
> Fixes #7519.
> ---
> I've had this lying around for a bit with intent to use it to support 
> non-hwaccel hardware decoders (in particular, v4l2m2m), but it actually fixes 
> the force-hwaccel use-case too in a sensible way.
> 
> 
>  doc/ffmpeg.texi  | 12 
>  fftools/ffmpeg.c |  4 
>  fftools/ffmpeg.h |  4 
>  fftools/ffmpeg_opt.c | 15 +++
>  4 files changed, 35 insertions(+)
> 
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index 3717f22d42..9f9e693898 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -920,6 +920,18 @@ would be more efficient.
>  When doing stream copy, copy also non-key frames found at the
>  beginning.
>  
> +@item -decode_format[:@var{stream_specifier}] @var{pixfmt} 
> (@emph{input,per-stream})
> +Set the output format to be used by the decoder for this stream.  If the
> +decoder does not natively support this format for the input stream then
> +decoding will fail rather than continuing with a different format.
> +
> +In general this should not be set - the decoder will select an output
> +format based on the input stream parameters and available components, and
> +that will be automatically converted to whatever the output requires.  It
> +may be useful to force a hardware decoder supporting output in multiple
> +different memory types to pick the desired one, or to ensure that a
> +hardware decoder is used when software fallback is also available.
> +
>  @item -init_hw_device 
> @var{type}[=@var{name}][:@var{device}[,@var{key=value}...]]
>  Initialise a new hardware device of type @var{type} called @var{name}, using 
> the
>  given device parameters.
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 38c21e944a..73bed55e4d 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2800,6 +2800,10 @@ static enum AVPixelFormat get_format(AVCodecContext 
> *s, const enum AVPixelFormat
>  const AVCodecHWConfig  *config = NULL;
>  int i;
>  
> +if (ist->decode_format != AV_PIX_FMT_NONE &&
> +ist->decode_format != *p)
> +continue;
> +
>  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
>  break;
>  
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index eb1eaf6363..88e0aa60ea 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -125,6 +125,8 @@ typedef struct OptionsContext {
>  intnb_ts_scale;
>  SpecifierOpt *dump_attachment;
>  intnb_dump_attachment;
> +SpecifierOpt *decode_formats;
> +intnb_decode_formats;
>  SpecifierOpt *hwaccels;
>  intnb_hwaccels;
>  SpecifierOpt *hwaccel_devices;

> @@ -334,6 +336,8 @@ typedef struct InputStream {
>  int top_field_first;
>  int guess_layout_max;
>  
> +enum AVPixelFormat decode_format;
> +

I think this should be a list and not a single format
either way, the patch LGTM

thx


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2018-11-12 Thread Eoff, Ullysses A
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, November 11, 2018 6:55 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode 
> format
> 
> Fixes #7519.
> ---
> I've had this lying around for a bit with intent to use it to support 
> non-hwaccel hardware decoders (in particular, v4l2m2m), but it
> actually fixes the force-hwaccel use-case too in a sensible way.
> 
> 
>  doc/ffmpeg.texi  | 12 
>  fftools/ffmpeg.c |  4 
>  fftools/ffmpeg.h |  4 
>  fftools/ffmpeg_opt.c | 15 +++
>  4 files changed, 35 insertions(+)
> 
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index 3717f22d42..9f9e693898 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -920,6 +920,18 @@ would be more efficient.
>  When doing stream copy, copy also non-key frames found at the
>  beginning.
> 
> +@item -decode_format[:@var{stream_specifier}] @var{pixfmt} 
> (@emph{input,per-stream})
> +Set the output format to be used by the decoder for this stream.  If the
> +decoder does not natively support this format for the input stream then
> +decoding will fail rather than continuing with a different format.
> +
> +In general this should not be set - the decoder will select an output
> +format based on the input stream parameters and available components, and
> +that will be automatically converted to whatever the output requires.  It
> +may be useful to force a hardware decoder supporting output in multiple
> +different memory types to pick the desired one, or to ensure that a
> +hardware decoder is used when software fallback is also available.
> +
>  @item -init_hw_device 
> @var{type}[=@var{name}][:@var{device}[,@var{key=value}...]]
>  Initialise a new hardware device of type @var{type} called @var{name}, using 
> the
>  given device parameters.
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 38c21e944a..73bed55e4d 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2800,6 +2800,10 @@ static enum AVPixelFormat get_format(AVCodecContext 
> *s, const enum AVPixelFormat
>  const AVCodecHWConfig  *config = NULL;
>  int i;
> 
> +if (ist->decode_format != AV_PIX_FMT_NONE &&
> +ist->decode_format != *p)
> +continue;
> +
>  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
>  break;
> 
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index eb1eaf6363..88e0aa60ea 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -125,6 +125,8 @@ typedef struct OptionsContext {
>  intnb_ts_scale;
>  SpecifierOpt *dump_attachment;
>  intnb_dump_attachment;
> +SpecifierOpt *decode_formats;
> +intnb_decode_formats;
>  SpecifierOpt *hwaccels;
>  intnb_hwaccels;
>  SpecifierOpt *hwaccel_devices;
> @@ -334,6 +336,8 @@ typedef struct InputStream {
>  int top_field_first;
>  int guess_layout_max;
> 
> +enum AVPixelFormat decode_format;
> +
>  int autorotate;
> 
>  int fix_sub_duration;
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index d4851a2cd8..0e3e8b99fe 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -701,6 +701,7 @@ static void add_input_streams(OptionsContext *o, 
> AVFormatContext *ic)
>  AVStream *st = ic->streams[i];
>  AVCodecParameters *par = st->codecpar;
>  InputStream *ist = av_mallocz(sizeof(*ist));
> +char *decode_format = NULL;
>  char *framerate = NULL, *hwaccel_device = NULL;
>  const char *hwaccel = NULL;
>  char *hwaccel_output_format = NULL;
> @@ -797,6 +798,17 @@ static void add_input_streams(OptionsContext *o, 
> AVFormatContext *ic)
>  ist->top_field_first = -1;
>  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, 
> ic, st);
> 
> +MATCH_PER_STREAM_OPT(decode_formats, str, decode_format, ic, st);
> +if (decode_format) {
> +ist->decode_format = av_get_pix_fmt(decode_format);
> +if (ist->decode_format == AV_PIX_FMT_NONE) {
> +av_log(NULL, AV_LOG_FATAL, "Unrecognised decode format: 
> %s",
> +   decode_format);
> +}
> +} else {
> +ist->decode_format = AV_PIX_FMT_NONE;
> +}
> +
>  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
>  if (hwaccel) {
> 

[FFmpeg-devel] [PATCH] ffmpeg: Add option to force a specific decode format

2018-11-11 Thread Mark Thompson
Fixes #7519.
---
I've had this lying around for a bit with intent to use it to support 
non-hwaccel hardware decoders (in particular, v4l2m2m), but it actually fixes 
the force-hwaccel use-case too in a sensible way.


 doc/ffmpeg.texi  | 12 
 fftools/ffmpeg.c |  4 
 fftools/ffmpeg.h |  4 
 fftools/ffmpeg_opt.c | 15 +++
 4 files changed, 35 insertions(+)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 3717f22d42..9f9e693898 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -920,6 +920,18 @@ would be more efficient.
 When doing stream copy, copy also non-key frames found at the
 beginning.
 
+@item -decode_format[:@var{stream_specifier}] @var{pixfmt} 
(@emph{input,per-stream})
+Set the output format to be used by the decoder for this stream.  If the
+decoder does not natively support this format for the input stream then
+decoding will fail rather than continuing with a different format.
+
+In general this should not be set - the decoder will select an output
+format based on the input stream parameters and available components, and
+that will be automatically converted to whatever the output requires.  It
+may be useful to force a hardware decoder supporting output in multiple
+different memory types to pick the desired one, or to ensure that a
+hardware decoder is used when software fallback is also available.
+
 @item -init_hw_device 
@var{type}[=@var{name}][:@var{device}[,@var{key=value}...]]
 Initialise a new hardware device of type @var{type} called @var{name}, using 
the
 given device parameters.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 38c21e944a..73bed55e4d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2800,6 +2800,10 @@ static enum AVPixelFormat get_format(AVCodecContext *s, 
const enum AVPixelFormat
 const AVCodecHWConfig  *config = NULL;
 int i;
 
+if (ist->decode_format != AV_PIX_FMT_NONE &&
+ist->decode_format != *p)
+continue;
+
 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
 break;
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index eb1eaf6363..88e0aa60ea 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -125,6 +125,8 @@ typedef struct OptionsContext {
 intnb_ts_scale;
 SpecifierOpt *dump_attachment;
 intnb_dump_attachment;
+SpecifierOpt *decode_formats;
+intnb_decode_formats;
 SpecifierOpt *hwaccels;
 intnb_hwaccels;
 SpecifierOpt *hwaccel_devices;
@@ -334,6 +336,8 @@ typedef struct InputStream {
 int top_field_first;
 int guess_layout_max;
 
+enum AVPixelFormat decode_format;
+
 int autorotate;
 
 int fix_sub_duration;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index d4851a2cd8..0e3e8b99fe 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -701,6 +701,7 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 AVStream *st = ic->streams[i];
 AVCodecParameters *par = st->codecpar;
 InputStream *ist = av_mallocz(sizeof(*ist));
+char *decode_format = NULL;
 char *framerate = NULL, *hwaccel_device = NULL;
 const char *hwaccel = NULL;
 char *hwaccel_output_format = NULL;
@@ -797,6 +798,17 @@ static void add_input_streams(OptionsContext *o, 
AVFormatContext *ic)
 ist->top_field_first = -1;
 MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, 
st);
 
+MATCH_PER_STREAM_OPT(decode_formats, str, decode_format, ic, st);
+if (decode_format) {
+ist->decode_format = av_get_pix_fmt(decode_format);
+if (ist->decode_format == AV_PIX_FMT_NONE) {
+av_log(NULL, AV_LOG_FATAL, "Unrecognised decode format: 
%s",
+   decode_format);
+}
+} else {
+ist->decode_format = AV_PIX_FMT_NONE;
+}
+
 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
 if (hwaccel) {
 // The NVDEC hwaccels use a CUDA device, so remap the name 
here.
@@ -3583,6 +3595,9 @@ const OptionDef options[] = {
 "audio bitrate (please use -b:a)", "bitrate" },
 { "b",OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT,  
  { .func_arg = opt_bitrate },
 "video bitrate (please use -b:v)", "bitrate" },
+{ "decode_format",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
+OPT_SPEC | OPT_INPUT,  
  { .off = OFFSET(decode_formats) },
+"set output format used by decoder, fail if this format is not 
available", "format" },
 { "hwaccel",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
   OPT_SPEC | OPT_INPUT,
  { .off = OFFSET(hwaccels) },
 "use HW accelerated decoding", "hwaccel name" },
-- 
2.19.1