summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-10-07 00:39:59 +0200
committerCarl Hetherington <cth@carlh.net>2022-10-18 01:14:05 +0200
commitec904906586478d8728c375c2bc71a568a07e062 (patch)
treee09747bbba18120c03d3a4c88d2be7a505c2bd20
parentb1022ee35df4c18256a1a1d8007eeb35cbe29f61 (diff)
Add VideoFilterGraph::process for Image.
-rw-r--r--src/lib/video_filter_graph.cc44
-rw-r--r--src/lib/video_filter_graph.h1
2 files changed, 45 insertions, 0 deletions
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 <libavfilter/buffersrc.h>
@@ -48,6 +49,49 @@ VideoFilterGraph::VideoFilterGraph (dcp::Size s, AVPixelFormat p, dcp::Fraction
}
+list<shared_ptr<const Image>>
+VideoFilterGraph::process(shared_ptr<const Image> 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<shared_ptr<const Image>> images;
+
+ while (true) {
+ if (av_buffersink_get_frame(_buffer_sink_context, _frame) < 0) {
+ break;
+ }
+
+ images.push_back(make_shared<Image>(_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<std::pair<std::shared_ptr<const Image>, int64_t>> process (AVFrame * frame);
+ std::list<std::shared_ptr<const Image>> process(std::shared_ptr<const Image> image);
protected:
std::string src_parameters () const override;