From: Carl Hetherington Date: Thu, 6 Oct 2022 22:39:59 +0000 (+0200) Subject: Add VideoFilterGraph::process for Image. X-Git-Tag: v2.16.31~8^2~6 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=ef32f407557e22662b41f9852f68523952360e4b Add VideoFilterGraph::process for Image. --- diff --git a/src/lib/video_filter_graph.cc b/src/lib/video_filter_graph.cc index 64f7deb19..26f858437 100644 --- a/src/lib/video_filter_graph.cc +++ b/src/lib/video_filter_graph.cc @@ -21,6 +21,7 @@ #include "compose.hpp" #include "image.h" +#include "scope_guard.h" #include "video_filter_graph.h" extern "C" { #include @@ -48,6 +49,49 @@ VideoFilterGraph::VideoFilterGraph (dcp::Size s, AVPixelFormat p, dcp::Fraction } +list> +VideoFilterGraph::process(shared_ptr image) +{ + if (_copy) { + return { image }; + } + + auto frame = av_frame_alloc(); + if (!frame) { + throw std::bad_alloc(); + } + + ScopeGuard sg = [&frame]() { av_frame_free(&frame); }; + + for (int i = 0; i < image->planes(); ++i) { + frame->data[i] = image->data()[i]; + frame->linesize[i] = image->stride()[i]; + } + + frame->width = image->size().width; + frame->height = image->size().height; + frame->format = image->pixel_format(); + + int r = av_buffersrc_write_frame(_buffer_src_context, frame); + if (r < 0) { + throw DecodeError(String::compose(N_("could not push buffer into filter chain (%1)."), r)); + } + + list> images; + + while (true) { + if (av_buffersink_get_frame(_buffer_sink_context, _frame) < 0) { + break; + } + + images.push_back(make_shared(_frame, Image::Alignment::PADDED)); + av_frame_unref (_frame); + } + + return images; +} + + /** Take an AVFrame and process it using our configured filters, returning a * set of Images. Caller handles memory management of the input frame. */ diff --git a/src/lib/video_filter_graph.h b/src/lib/video_filter_graph.h index e120fb467..1fb322282 100644 --- a/src/lib/video_filter_graph.h +++ b/src/lib/video_filter_graph.h @@ -29,6 +29,7 @@ public: bool can_process (dcp::Size s, AVPixelFormat p) const; std::list, int64_t>> process (AVFrame * frame); + std::list> process(std::shared_ptr image); protected: std::string src_parameters () const override;