Quoting Mark Thompson (2017-04-23 21:21:02)
> This only supports one device globally, but more can be used by
> passing them with input streams in hw_frames_ctx or by deriving new
> devices inside a filter graph with hwmap.
> ---
> Added doc.
> 
> 
>  avtools/avconv.h        |  1 +
>  avtools/avconv_filter.c | 10 ++++++++--
>  avtools/avconv_opt.c    | 21 +++++++++++++++++++++
>  doc/avconv.texi         | 11 +++++++++++
>  4 files changed, 41 insertions(+), 2 deletions(-)
> 
> diff --git a/avtools/avconv.h b/avtools/avconv.h
> index 9415b208b..3354c5044 100644
> --- a/avtools/avconv.h
> +++ b/avtools/avconv.h
> @@ -489,6 +489,7 @@ extern const OptionDef options[];
>  extern const HWAccel hwaccels[];
>  extern int hwaccel_lax_profile_check;
>  extern AVBufferRef *hw_device_ctx;
> +extern HWDevice *filter_hw_device;
>  
>  void reset_options(OptionsContext *o);
>  void show_usage(void);
> diff --git a/avtools/avconv_filter.c b/avtools/avconv_filter.c
> index e53dcd271..884478da2 100644
> --- a/avtools/avconv_filter.c
> +++ b/avtools/avconv_filter.c
> @@ -711,9 +711,15 @@ int configure_filtergraph(FilterGraph *fg)
>      if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, 
> &outputs)) < 0)
>          goto fail;
>  
> -    if (hw_device_ctx) {
> +    if (filter_hw_device || hw_device_ctx) {
> +        AVBufferRef *device = filter_hw_device ? filter_hw_device->device_ref
> +                                               : hw_device_ctx;
>          for (i = 0; i < fg->graph->nb_filters; i++) {
> -            fg->graph->filters[i]->hw_device_ctx = 
> av_buffer_ref(hw_device_ctx);
> +            fg->graph->filters[i]->hw_device_ctx = av_buffer_ref(device);
> +            if (!fg->graph->filters[i]->hw_device_ctx) {
> +                ret = AVERROR(ENOMEM);
> +                goto fail;
> +            }
>          }
>      }
>  
> diff --git a/avtools/avconv_opt.c b/avtools/avconv_opt.c
> index e970c8e46..cdc980870 100644
> --- a/avtools/avconv_opt.c
> +++ b/avtools/avconv_opt.c
> @@ -80,6 +80,7 @@ const HWAccel hwaccels[] = {
>  };
>  int hwaccel_lax_profile_check = 0;
>  AVBufferRef *hw_device_ctx;
> +HWDevice *filter_hw_device;
>  
>  char *vstats_filename;
>  
> @@ -369,6 +370,24 @@ static int opt_init_hw_device(void *optctx, const char 
> *opt, const char *arg)
>      }
>  }
>  
> +static int opt_filter_hw_device(void *optctx, const char *opt, const char 
> *arg)
> +{
> +    int err;
> +    if (filter_hw_device) {
> +        av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
> +        return AVERROR(EINVAL);
> +    }
> +    filter_hw_device = hw_device_get_by_name(arg);
> +    if (!filter_hw_device) {
> +        err = hw_device_init_from_string(arg, &filter_hw_device);

Do we really want this fallback? Seems to me this might cause more
confusion since now stuff depends on the ordering of -filter_hw_device
and -init_hw_device

> diff --git a/doc/avconv.texi b/doc/avconv.texi
> index 7bcb78797..2837e30f3 100644
> --- a/doc/avconv.texi
> +++ b/doc/avconv.texi
> @@ -644,6 +644,17 @@ deriving it from the existing device with the name 
> @var{source}.
>  @item -init_hw_device list
>  List all hardware device types supported in this build of avconv.
>  
> +@item -filter_hw_device @var{name}
> +Pass the hardware device called @var{name} to all filters in any filter 
> graph.
> +This can be used to set the device to upload to with the @code{hwupload} 
> filter,
> +or the device to map to with the @code{hwmap} filter.  Other filters may also
> +make use of this parameter when they require a hardware device.  Note that 
> this
> +is typically only required when the input is not already in hardware frames -
> +when it is, filters will derive the device they require from the context of 
> the
> +frames they receive as input.
> +
> +This is a global setting, so all filters will receive the same device.
> +

Maybe mention that this is a (hopefully) temporary thing and people
shouldn't rely on this option in scripts and such.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to