On Thu, 2 Feb 2017 14:13:04 +0000 Mark Thompson <s...@jkqxz.net> wrote:
> On 02/02/17 13:34, wm4 wrote: > > On Thu, 2 Feb 2017 12:49:56 +0000 > > Mark Thompson <s...@jkqxz.net> wrote: > > > >> --- > >> This is now needed independently of hwaccel setup because it has to happen > >> before avcodec_open2(). > >> > >> > >> avconv.c | 13 +++++++++++++ > >> 1 file changed, 13 insertions(+) > >> > >> diff --git a/avconv.c b/avconv.c > >> index 94b6da2..0536e72 100644 > >> --- a/avconv.c > >> +++ b/avconv.c > >> @@ -1703,6 +1703,13 @@ static int init_input_stream(int ist_index, char > >> *error, int error_len) > >> > >> if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) > >> av_dict_set(&ist->decoder_opts, "threads", "auto", 0); > >> + > >> + if (hw_device_ctx) { > >> + ist->dec_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx); > >> + if (!ist->dec_ctx->hw_device_ctx) > >> + return AVERROR(ENOMEM); > >> + } > >> + > >> if ((ret = avcodec_open2(ist->dec_ctx, codec, > >> &ist->decoder_opts)) < 0) { > >> char errbuf[128]; > >> if (ret == AVERROR_EXPERIMENTAL) > >> @@ -2039,6 +2046,12 @@ static int init_output_stream(OutputStream *ost, > >> char *error, int error_len) > >> if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) > >> av_dict_set(&ost->encoder_opts, "threads", "auto", 0); > >> > >> + if (hw_device_ctx) { > >> + ost->enc_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx); > >> + if (!ost->enc_ctx->hw_device_ctx) > >> + return AVERROR(ENOMEM); > >> + } > >> + > >> if (ost->filter && ost->filter->filter->inputs[0]->hw_frames_ctx > >> && > >> > >> ((AVHWFramesContext*)ost->filter->filter->inputs[0]->hw_frames_ctx->data)->format > >> == > >> ost->filter->filter->inputs[0]->format) { > > > > Shouldn't it try to use the device from the filter's hw_frames_ctx > > (which you see in the diff context)? > > Hmm, yes. It would be better to only set it if hw_frames_ctx is not set. At least that would make it more consistent. > > Also, could setting the hw_device_ctx unconditionally on input have > > weird side-effect, like decoders behaving differently from before? > > (E.g. would have created their own context if it isn't set, or could > > pick up an incompatible device context meant for the encoder.) > > Possibly, but not until any decoders actually use the field. I am preparing > more patches to add support for different device types in avconv (rather than > the single global device), which will hopefully mitigate at least the > incompatible device problem. Sounds good then. _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel