From 05c37b9bb09f7bfa4c2ec8ea6b3fa4a83d0fec20 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 14 Nov 2012 20:04:15 +0000 Subject: Tests pass again. --- src/lib/ffmpeg_decoder.cc | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 78d0c48c4..3767d7c5f 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -47,12 +47,14 @@ extern "C" { #include "util.h" #include "log.h" #include "ffmpeg_decoder.h" +#include "filter_graph.h" #include "subtitle.h" using std::cout; using std::string; using std::vector; using std::stringstream; +using std::list; using boost::shared_ptr; using boost::optional; @@ -223,7 +225,7 @@ FFmpegDecoder::pass () int frame_finished; while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { - process_video (_frame); + filter_and_emit_video (_frame); } if (_audio_stream && _opt->decode_audio && _film->use_content_audio()) { @@ -233,7 +235,7 @@ FFmpegDecoder::pass () ); assert (_audio_codec_context->channels == _film->audio_channels()); - process_audio (deinterleave_audio (_frame->data[0], data_size)); + Audio (deinterleave_audio (_frame->data[0], data_size)); } } @@ -283,7 +285,7 @@ FFmpegDecoder::pass () if (delta > -one_frame) { /* Process this frame */ - process_video (_frame); + filter_and_emit_video (_frame); } else { /* Otherwise we are omitting a frame to keep things right */ _film->log()->log (String::compose ("Frame removed at %1s", out_pts_seconds)); @@ -326,7 +328,7 @@ FFmpegDecoder::pass () if (s) { shared_ptr audio (new AudioBuffers (_audio_stream.get().channels(), s)); audio->make_silent (); - process_audio (audio); + Audio (audio); } } @@ -335,7 +337,7 @@ FFmpegDecoder::pass () ); assert (_audio_codec_context->channels == _film->audio_channels()); - process_audio (deinterleave_audio (_frame->data[0], data_size)); + Audio (deinterleave_audio (_frame->data[0], data_size)); } } @@ -348,9 +350,9 @@ FFmpegDecoder::pass () indicate that the previous subtitle should stop. */ if (sub.num_rects > 0) { - process_subtitle (shared_ptr (new TimedSubtitle (sub, _first_video.get()))); + emit_subtitle (shared_ptr (new TimedSubtitle (sub, _first_video.get()))); } else { - process_subtitle (shared_ptr ()); + emit_subtitle (shared_ptr ()); } avsubtitle_free (&sub); } @@ -527,3 +529,28 @@ FFmpegDecoder::set_subtitle_stream (optional s) Decoder::set_subtitle_stream (s); setup_subtitle (); } + +void +FFmpegDecoder::filter_and_emit_video (AVFrame* frame) +{ + shared_ptr graph; + + list >::iterator i = _filter_graphs.begin(); + while (i != _filter_graphs.end() && !(*i)->can_process (Size (frame->width, frame->height), (AVPixelFormat) frame->format)) { + ++i; + } + + if (i == _filter_graphs.end ()) { + graph.reset (new FilterGraph (_film, this, _opt->apply_crop, Size (frame->width, frame->height), (AVPixelFormat) frame->format)); + _filter_graphs.push_back (graph); + _film->log()->log (String::compose ("New graph for %1x%2, pixel format %3", frame->width, frame->height, frame->format)); + } else { + graph = *i; + } + + list > images = graph->process (frame); + + for (list >::iterator i = images.begin(); i != images.end(); ++i) { + emit_video (*i); + } +} -- cgit v1.2.3