2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "video_filter_graph.h"
22 #include "compose.hpp"
24 #include <libavfilter/buffersrc.h>
25 #include <libavfilter/buffersink.h>
35 using boost::shared_ptr;
37 VideoFilterGraph::VideoFilterGraph (dcp::Size s, AVPixelFormat p)
44 /** Take an AVFrame and process it using our configured filters, returning a
45 * set of Images. Caller handles memory management of the input frame.
47 list<pair<shared_ptr<Image>, int64_t> >
48 VideoFilterGraph::process (AVFrame* frame)
50 list<pair<shared_ptr<Image>, int64_t> > images;
53 images.push_back (make_pair (shared_ptr<Image> (new Image (frame)), av_frame_get_best_effort_timestamp (frame)));
55 int r = av_buffersrc_write_frame (_buffer_src_context, frame);
57 throw DecodeError (String::compose (N_("could not push buffer into filter chain (%1)."), r));
61 if (av_buffersink_get_frame (_buffer_sink_context, _frame) < 0) {
65 images.push_back (make_pair (shared_ptr<Image> (new Image (_frame)), av_frame_get_best_effort_timestamp (_frame)));
66 av_frame_unref (_frame);
73 /** @param s Image size.
74 * @param p Pixel format.
75 * @return true if this chain can process images with `s' and `p', otherwise false.
78 VideoFilterGraph::can_process (dcp::Size s, AVPixelFormat p) const
80 return (_size == s && _pixel_format == p);
84 VideoFilterGraph::src_parameters () const
88 a << "video_size=" << _size.width << "x" << _size.height << ":"
89 << "pix_fmt=" << _pixel_format << ":"
91 << "pixel_aspect=1/1";
97 VideoFilterGraph::sink_parameters () const
99 AVBufferSinkParams* sink_params = av_buffersink_params_alloc ();
100 AVPixelFormat* pixel_fmts = new AVPixelFormat[2];
101 pixel_fmts = new AVPixelFormat[2];
102 pixel_fmts[0] = _pixel_format;
103 pixel_fmts[1] = AV_PIX_FMT_NONE;
104 sink_params->pixel_fmts = pixel_fmts;
109 VideoFilterGraph::src_name () const
115 VideoFilterGraph::sink_name () const