#include "filter.h"
#include "exceptions.h"
#include "image.h"
-#include "film.h"
#include "ffmpeg_decoder.h"
#include "i18n.h"
using std::string;
using std::list;
using boost::shared_ptr;
+using boost::weak_ptr;
using libdcp::Size;
-/** Construct a FilterGraph for the settings in a film.
- * @param film Film.
- * @param decoder Decoder that we are using.
+/** Construct a FilterGraph for the settings in a piece of content.
+ * @param content Content.
* @param s Size of the images to process.
* @param p Pixel format of the images to process.
*/
-FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p)
+FilterGraph::FilterGraph (shared_ptr<const FFmpegContent> content, libdcp::Size s, AVPixelFormat p)
: _buffer_src_context (0)
, _buffer_sink_context (0)
, _size (s)
, _pixel_format (p)
{
- string filters = Filter::ffmpeg_strings (film->filters()).first;
+ _frame = av_frame_alloc ();
+
+ string filters = Filter::ffmpeg_strings (content->filters()).first;
if (!filters.empty ()) {
- filters += N_(",");
+ filters += ",";
}
- filters += crop_string (Position (film->crop().left, film->crop().top), film->cropped_size (decoder->native_size()));
+ Crop crop = content->crop ();
+ libdcp::Size cropped_size = _size;
+ cropped_size.width -= crop.left + crop.right;
+ cropped_size.height -= crop.top + crop.bottom;
+ filters += crop_string (Position (crop.left, crop.top), cropped_size);
AVFilterGraph* graph = avfilter_graph_alloc();
if (graph == 0) {
stringstream a;
a << "video_size=" << _size.width << "x" << _size.height << ":"
<< "pix_fmt=" << _pixel_format << ":"
- << "time_base=" << decoder->time_base_numerator() << "/" << decoder->time_base_denominator() << ":"
- << "pixel_aspect=" << decoder->sample_aspect_ratio_numerator() << "/" << decoder->sample_aspect_ratio_denominator();
+ << "time_base=0/1:"
+ << "pixel_aspect=0/1";
int r;
/* XXX: leaking `inputs' / `outputs' ? */
}
+FilterGraph::~FilterGraph ()
+{
+ av_frame_free (&_frame);
+}
+
/** Take an AVFrame and process it using our configured filters, returning a
- * set of Images.
+ * set of Images. Caller handles memory management of the input frame.
*/
list<shared_ptr<Image> >
FilterGraph::process (AVFrame* frame)
}
while (1) {
- AVFrame* frame = av_frame_alloc ();
- if (av_buffersink_get_frame (_buffer_sink_context, frame) < 0) {
- av_frame_free (&frame);
+ if (av_buffersink_get_frame (_buffer_sink_context, _frame) < 0) {
break;
}
- /* This takes ownership of the AVFrame */
- images.push_back (shared_ptr<Image> (new FrameImage (frame, true)));
+ images.push_back (shared_ptr<Image> (new SimpleImage (_frame)));
}
return images;