#include <stdint.h>
#include <boost/lexical_cast.hpp>
extern "C" {
-#include <tiffio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
#include <sndfile.h>
#include "film.h"
-#include "format.h"
-#include "transcoder.h"
-#include "job.h"
#include "filter.h"
#include "exceptions.h"
#include "image.h"
boost::mutex FFmpegDecoder::_mutex;
-FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegContent> c, bool video, bool audio, bool subtitles)
+FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegContent> c, bool video, bool audio)
: Decoder (f)
, VideoDecoder (f, c)
, AudioDecoder (f, c)
, _subtitle_codec (0)
, _decode_video (video)
, _decode_audio (audio)
- , _decode_subtitles (subtitles)
{
setup_general ();
setup_video ();
if (_ffmpeg_content->audio_stream() && _decode_audio) {
decode_audio_packet ();
}
-
+
+ /* Stop us being asked for any more data */
+ _next_video = _next_audio = _ffmpeg_content->length ();
return;
}
decode_video_packet ();
} else if (_ffmpeg_content->audio_stream() && _packet.stream_index == _ffmpeg_content->audio_stream()->id && _decode_audio) {
decode_audio_packet ();
- } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id && _decode_subtitles) {
+ } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id) {
int got_subtitle;
AVSubtitle sub;
}
avsubtitle_free (&sub);
}
+ } else {
+ cout << "[ffmpeg] other packet.\n";
}
av_free_packet (&_packet);
FFmpegDecoder::seek (Time t)
{
do_seek (t, false, false);
+ VideoDecoder::seek (t);
}
void
FFmpegDecoder::seek_back ()
{
- if (next() < 2.5) {
+ if (next() < (2.5 * TIME_HZ / video_frame_rate())) {
return;
}
do_seek (next() - 2.5 * TIME_HZ / video_frame_rate(), true, true);
+ VideoDecoder::seek_back ();
}
void
FFmpegDecoder::seek_forward ()
{
- if (next() >= (video_length() - video_frame_rate())) {
+ if (next() >= (_ffmpeg_content->length() - 0.5 * TIME_HZ / video_frame_rate())) {
return;
}
do_seek (next() - 0.5 * TIME_HZ / video_frame_rate(), true, true);
+ VideoDecoder::seek_forward ();
}
void
FFmpegDecoder::do_seek (Time t, bool backwards, bool accurate)
{
int64_t const vt = t / (av_q2d (_format_context->streams[_video_stream]->time_base) * TIME_HZ);
- cout << "seek-> " << t << "\n";
av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0);
avcodec_flush_buffers (_video_codec_context);
return;
}
-void
-FFmpegDecoder::film_changed (Film::Property p)
-{
- switch (p) {
- case Film::FILTERS:
- {
- boost::mutex::scoped_lock lm (_filter_graphs_mutex);
- _filter_graphs.clear ();
- }
- break;
-
- default:
- break;
- }
-}
-
/** @return Length (in video frames) according to our content's header */
ContentVideoFrame
FFmpegDecoder::video_length () const
);
assert (_audio_codec_context->channels == _ffmpeg_content->audio_channels());
- Audio (deinterleave_audio (_frame->data, data_size), source_pts_seconds);
+ audio (deinterleave_audio (_frame->data, data_size), source_pts_seconds);
}
copy_packet.data += decode_result;
}
if (i == _filter_graphs.end ()) {
- graph.reset (new FilterGraph (_film, this, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format));
- _filter_graphs.push_back (graph);
-
shared_ptr<const Film> film = _film.lock ();
assert (film);
+
+ graph.reset (new FilterGraph (_ffmpeg_content, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format));
+ _filter_graphs.push_back (graph);
+
film->log()->log (String::compose (N_("New graph for %1x%2, pixel format %3"), _frame->width, _frame->height, _frame->format));
} else {
graph = *i;
}
-
list<shared_ptr<Image> > images = graph->process (_frame);
+
+ string post_process = Filter::ffmpeg_strings (_ffmpeg_content->filters()).second;
for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
+
+ shared_ptr<Image> image = *i;
+ if (!post_process.empty ()) {
+ image = image->post_process (post_process, true);
+ }
+
int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
if (bet != AV_NOPTS_VALUE) {
/* XXX: may need to insert extra frames / remove frames here ...
(as per old Matcher)
*/
Time const t = bet * av_q2d (_format_context->streams[_video_stream]->time_base) * TIME_HZ;
- video (*i, false, t);
+ video (image, false, t);
} else {
shared_ptr<const Film> film = _film.lock ();
assert (film);
Time
FFmpegDecoder::next () const
{
- return min (_next_video, _next_audio);
+ if (_decode_video && _decode_audio && _audio_codec_context) {
+ return min (_next_video, _next_audio);
+ }
+
+ if (_decode_audio && _audio_codec_context) {
+ return _next_audio;
+ }
+
+ return _next_video;
+}
+
+bool
+FFmpegDecoder::done () const
+{
+ return (!_decode_audio || !_audio_codec_context || audio_done()) && (!_decode_video || video_done());
}
+