diff --git a/ffmpeg.c b/ffmpeg.c index b9c15981fc..5e137c61bd 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2049,7 +2049,22 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int if (!frame_sample_aspect->num) *frame_sample_aspect = ist->st->sample_aspect_ratio; decoded_frame->pts = ist->pts; + if (ist->st->codec->codec->capabilities & CODEC_CAP_DR1) { + FrameBuffer *buf = decoded_frame->opaque; + AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays( + decoded_frame->data, decoded_frame->linesize, + AV_PERM_READ | AV_PERM_PRESERVE, + ist->st->codec->width, ist->st->codec->height, + ist->st->codec->pix_fmt); + avfilter_copy_frame_props(fb, decoded_frame); + fb->pts = ist->pts; + fb->buf->priv = buf; + fb->buf->free = filter_release_buffer; + + buf->refcount++; + av_buffersrc_buffer(ost->input_video_filter, fb); + } else if((av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, AV_VSRC_BUF_FLAG_OVERWRITE)) < 0){ av_log(0, AV_LOG_FATAL, "Failed to inject frame into filter network\n"); exit_program(1); @@ -2275,6 +2290,13 @@ static int init_input_stream(int ist_index, OutputStream *output_streams, int nb avcodec_get_name(ist->st->codec->codec_id), ist->file_index, ist->st->index); return AVERROR(EINVAL); } + + if (codec->type == AVMEDIA_TYPE_VIDEO && codec->capabilities & CODEC_CAP_DR1) { + ist->st->codec->get_buffer = codec_get_buffer; + ist->st->codec->release_buffer = codec_release_buffer; + ist->st->codec->opaque = ist; + } + if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) { snprintf(error, error_len, "Error while opening decoder for input stream #%d:%d", ist->file_index, ist->st->index);