From a605b22381ee47d2737307e0b61e3423b020547b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 10 Dec 2012 20:37:38 +0000 Subject: Try removing force of single-threaded decoding again. --- src/lib/ffmpeg_decoder.cc | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 9b89ffffc..748fb9d7e 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -154,13 +154,6 @@ FFmpegDecoder::setup_video () throw DecodeError ("could not find video decoder"); } - /* I think this prevents problems with green hash on decodes and - "changing frame properties on the fly is not supported by all filters" - messages with some content. Although I'm not sure; needs checking. - */ - AVDictionary* opts = 0; - av_dict_set (&opts, "threads", "1", 0); - if (avcodec_open2 (_video_codec_context, _video_codec, &opts) < 0) { throw DecodeError ("could not open video decoder"); } -- cgit v1.2.3 From 88e187267df754a99dba3222a94e01362986f720 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 10 Dec 2012 20:50:22 +0000 Subject: Oops in previous. --- src/lib/ffmpeg_decoder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 748fb9d7e..ef9c05fa6 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -154,7 +154,7 @@ FFmpegDecoder::setup_video () throw DecodeError ("could not find video decoder"); } - if (avcodec_open2 (_video_codec_context, _video_codec, &opts) < 0) { + if (avcodec_open2 (_video_codec_context, _video_codec, 0) < 0) { throw DecodeError ("could not open video decoder"); } } -- cgit v1.2.3 From e9d0d7bf9871b7e7fa8d154535cf0bbc7e7bd466 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 10 Dec 2012 22:20:39 +0000 Subject: Try to allow users to specify that the film's header should be trusted wrt length when building thumbnails, thus speeding up examine-content by a factor of 2-ish. --- src/lib/examine_content_job.cc | 83 ++++++++++++++++++++++++++++-------------- src/lib/ffmpeg_decoder.cc | 6 +++ src/lib/ffmpeg_decoder.h | 3 +- src/lib/film.cc | 2 +- src/lib/imagemagick_decoder.h | 5 +++ src/lib/transcoder.cc | 8 ++-- src/lib/transcoder.h | 4 ++ src/lib/video_decoder.h | 2 + wscript | 2 +- 9 files changed, 81 insertions(+), 34 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/examine_content_job.cc b/src/lib/examine_content_job.cc index 8db74801f..93333605b 100644 --- a/src/lib/examine_content_job.cc +++ b/src/lib/examine_content_job.cc @@ -60,51 +60,78 @@ ExamineContentJob::name () const void ExamineContentJob::run () { - /* Decode the content to get an accurate length */ + float progress_remaining = 1; - /* We don't want to use any existing length here, as progress - will be messed up. + /* Set the film's length to either + a) a length judged by running through the content or + b) the length from a decoder's header. */ - _film->unset_length (); - - shared_ptr o (new Options ("", "", "")); - o->out_size = Size (512, 512); - o->apply_crop = false; - o->decode_audio = false; - - descend (0.5); - pair, shared_ptr > decoders = decoder_factory (_film, o, this); + if (!_film->trust_content_header()) { + /* Decode the content to get an accurate length */ + + /* We don't want to use any existing length here, as progress + will be messed up. + */ + _film->unset_length (); + + shared_ptr o (new Options ("", "", "")); + o->out_size = Size (512, 512); + o->apply_crop = false; + o->decode_audio = false; + + descend (0.5); + + pair, shared_ptr > decoders = decoder_factory (_film, o, this); + + set_progress_unknown (); + while (!decoders.first->pass()) { + /* keep going */ + } + + _film->set_length (decoders.first->video_frame()); + + _film->log()->log (String::compose ("Video length examined as %1 frames", _film->length().get())); + + ascend (); + + progress_remaining -= 0.5; + + } else { - set_progress_unknown (); - while (!decoders.first->pass()) { - /* keep going */ + /* Get a quick decoder to get the content's length from its header. + It would have been nice to just use the thumbnail transcoder's decoder, + but that's a bit fiddly, and this isn't too expensive. + */ + + shared_ptr o (new Options ("", "", "")); + o->out_size = Size (1024, 1024); + pair, shared_ptr > d = decoder_factory (_film, o, 0); + _film->set_length (d.first->length()); + + _film->log()->log (String::compose ("Video length obtained from header as %1 frames", _film->length().get())); } - _film->set_length (decoders.first->video_frame()); - - _film->log()->log (String::compose ("Video length is %1 frames", _film->length())); - - ascend (); - /* Now make thumbnails for it */ - descend (0.5); + descend (progress_remaining); try { - o.reset (new Options (_film->dir ("thumbs"), ".png", "")); + shared_ptr o (new Options (_film->dir ("thumbs"), ".png", "")); o->out_size = _film->size (); o->apply_crop = false; o->decode_audio = false; - if (_film->length() > 0) { - o->decode_video_skip = _film->length().get() / 128; - } else { - o->decode_video_skip = 0; - } + o->decode_video_skip = _film->length().get() / 128; o->decode_subtitles = true; shared_ptr e (new ImageMagickEncoder (_film, o)); Transcoder w (_film, o, this, e); w.go (); + + /* Now set the film's length from the transcoder's decoder, since we + went to all the trouble of going through the content. + */ + + _film->set_length (w.video_decoder()->video_frame()); } catch (std::exception& e) { diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index ef9c05fa6..fd522a5ac 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -629,3 +629,9 @@ FFmpegAudioStream::to_string () const return String::compose ("ffmpeg %1 %2 %3 %4", _id, _sample_rate, _channel_layout, _name); } +/** @return Length (in video frames) according to our content's header */ +SourceFrame +FFmpegDecoder::length () const +{ + return (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second(); +} diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 87eebe1ec..1771551fc 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -56,7 +56,7 @@ public: , _name (n) , _id (i) {} - + std::string to_string () const; std::string name () const { @@ -89,6 +89,7 @@ public: float frames_per_second () const; Size native_size () const; + SourceFrame length () const; int time_base_numerator () const; int time_base_denominator () const; int sample_aspect_ratio_numerator () const; diff --git a/src/lib/film.cc b/src/lib/film.cc index 563147f68..e2a4cbeda 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1003,7 +1003,7 @@ Film::set_trust_content_header (bool t) signal_changed (TRUST_CONTENT_HEADER); - if (!_trust_content_header) { + if (!_trust_content_header) && !content().empty()) { /* We just said that we don't trust the content's header */ examine_content (); } diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h index f636191f2..de49c1b56 100644 --- a/src/lib/imagemagick_decoder.h +++ b/src/lib/imagemagick_decoder.h @@ -35,6 +35,11 @@ public: Size native_size () const; + SourceFrame length () const { + /* We don't know */ + return 0; + } + int audio_channels () const { return 0; } diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index 537b9b664..a7e79b05f 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -64,7 +64,9 @@ Transcoder::Transcoder (shared_ptr f, shared_ptr o, Job* j, /* Set up the decoder to use the film's set streams */ _decoders.first->set_subtitle_stream (f->subtitle_stream ()); - _decoders.second->set_audio_stream (f->audio_stream ()); + if (_decoders.second) { + _decoders.second->set_audio_stream (f->audio_stream ()); + } if (_matcher) { _decoders.first->connect_video (_matcher); @@ -73,7 +75,7 @@ Transcoder::Transcoder (shared_ptr f, shared_ptr o, Job* j, _decoders.first->connect_video (_encoder); } - if (_matcher && _delay_line) { + if (_matcher && _delay_line && _decoders.second) { _decoders.second->connect_audio (_delay_line); _delay_line->connect_audio (_matcher); _matcher->connect_audio (_gain); @@ -97,7 +99,7 @@ Transcoder::go () _decoders.first->set_progress (); } - if (!done[1] && dynamic_pointer_cast (_decoders.second) != dynamic_pointer_cast (_decoders.first)) { + if (!done[1] && _decoders.second && dynamic_pointer_cast (_decoders.second) != dynamic_pointer_cast (_decoders.first)) { done[1] = _decoders.second->pass (); } else { done[1] = true; diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h index e3ca2bb32..4a9667b3c 100644 --- a/src/lib/transcoder.h +++ b/src/lib/transcoder.h @@ -49,6 +49,10 @@ public: void go (); + boost::shared_ptr video_decoder () const { + return _decoders.first; + } + protected: /** A Job that is running this Transcoder, or 0 */ Job* _job; diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h index ea1899840..685138a58 100644 --- a/src/lib/video_decoder.h +++ b/src/lib/video_decoder.h @@ -33,6 +33,8 @@ public: virtual float frames_per_second () const = 0; /** @return native size in pixels */ virtual Size native_size () const = 0; + /** @return length (in source video frames), according to our content's header */ + virtual SourceFrame length () const = 0; virtual int time_base_numerator () const = 0; virtual int time_base_denominator () const = 0; diff --git a/wscript b/wscript index b0ca5d49d..290bf9b52 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ import os import sys APPNAME = 'dvdomatic' -VERSION = '0.59beta5' +VERSION = '0.60pre' def options(opt): opt.load('compiler_cxx') -- cgit v1.2.3 From 89319eb1217c8caca80dc22ca770766f6d2f26c0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 15 Dec 2012 18:16:35 +0000 Subject: Skipping hacks. --- src/lib/encoder.cc | 5 -- src/lib/ffmpeg_decoder.cc | 109 ++++++++++++++++++++++++++--------------- src/lib/ffmpeg_decoder.h | 3 ++ src/lib/film.cc | 2 +- src/lib/imagemagick_encoder.cc | 3 ++ src/lib/options.h | 9 +++- src/lib/transcoder.cc | 6 ++- src/lib/transcoder.h | 2 + src/wx/wx_util.cc | 5 +- 9 files changed, 95 insertions(+), 49 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 17a6726a6..dfb154f72 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -107,11 +107,6 @@ Encoder::frame_skipped () void Encoder::process_video (shared_ptr i, boost::shared_ptr s) { - if (_opt->decode_video_skip != 0 && (_video_frame % _opt->decode_video_skip) != 0) { - ++_video_frame; - return; - } - if (_opt->video_decode_range) { pair const r = _opt->video_decode_range.get(); if (_video_frame < r.first || _video_frame >= r.second) { diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index acaf149f4..1e473b6a3 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -265,46 +265,10 @@ FFmpegDecoder::pass () _film->log()->log (String::compose ("Used only %1 bytes of %2 in packet", r, _packet.size)); } - /* Where we are in the output, in seconds */ - double const out_pts_seconds = video_frame() / frames_per_second(); - - /* Where we are in the source, in seconds */ - double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) - * av_frame_get_best_effort_timestamp(_frame); - - _film->log()->log ( - String::compose ("Source video frame ready; source at %1, output at %2", source_pts_seconds, out_pts_seconds), - Log::VERBOSE - ); - - if (!_first_video) { - _first_video = source_pts_seconds; - } - - /* Difference between where we are and where we should be */ - double const delta = source_pts_seconds - _first_video.get() - out_pts_seconds; - double const one_frame = 1 / frames_per_second(); - - /* Insert frames if required to get out_pts_seconds up to pts_seconds */ - if (delta > one_frame) { - int const extra = rint (delta / one_frame); - for (int i = 0; i < extra; ++i) { - repeat_last_video (); - _film->log()->log ( - String::compose ( - "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)", - out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second() - ) - ); - } - } - - if (delta > -one_frame) { - /* Process this frame */ - filter_and_emit_video (_frame); + if (_opt->rough_decode_video_skip) { + rough_video_output (); } else { - /* Otherwise we are omitting a frame to keep things right */ - _film->log()->log (String::compose ("Frame removed at %1s", out_pts_seconds)); + precise_video_output (); } } @@ -637,3 +601,70 @@ FFmpegDecoder::length () const { return (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second(); } + +void +FFmpegDecoder::precise_video_output () +{ + /* Where we are in the output, in seconds */ + double const out_pts_seconds = video_frame() / frames_per_second(); + + /* Where we are in the source, in seconds */ + double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) + * av_frame_get_best_effort_timestamp(_frame); + + _film->log()->log ( + String::compose ("Source video frame ready; source at %1, output at %2", source_pts_seconds, out_pts_seconds), + Log::VERBOSE + ); + + if (!_first_video) { + _first_video = source_pts_seconds; + } + + /* Difference between where we are and where we should be */ + double const delta = source_pts_seconds - _first_video.get() - out_pts_seconds; + double const one_frame = 1 / frames_per_second(); + + /* Insert frames if required to get out_pts_seconds up to pts_seconds */ + if (delta > one_frame) { + int const extra = rint (delta / one_frame); + for (int i = 0; i < extra; ++i) { + repeat_last_video (); + _film->log()->log ( + String::compose ( + "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)", + out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second() + ) + ); + } + } + + if (delta > -one_frame) { + /* Process this 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)); + } +} + +void +FFmpegDecoder::rough_video_output () +{ + /* Where we are in the source, in seconds */ + double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) + * av_frame_get_best_effort_timestamp(_frame); + + if (!_last_rough_output || _last_rough_output.get() != source_pts_seconds) { + filter_and_emit_video (_frame); + _last_rough_output = source_pts_seconds; + } + + int64_t const t = static_cast(f) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second()); + cout << "seek to " << t << " in stream tb\n"; + int const r = av_seek_frame (_format_context, _video_stream, t, 0); + avcodec_flush_buffers (_video_codec_context); + if (r < 0) { + cout << "seek to " << t << " failed.\n"; + } +} diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 1771551fc..141b40da0 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -105,6 +105,8 @@ private: AVSampleFormat audio_sample_format () const; int bytes_per_audio_sample () const; + void rough_video_output (); + void precise_video_output (); void filter_and_emit_video (AVFrame *); void setup_general (); @@ -133,6 +135,7 @@ private: boost::optional _first_video; boost::optional _first_audio; + boost::optional _last_rough_output; std::list > _filter_graphs; }; diff --git a/src/lib/film.cc b/src/lib/film.cc index e2a4cbeda..ecf37f033 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1003,7 +1003,7 @@ Film::set_trust_content_header (bool t) signal_changed (TRUST_CONTENT_HEADER); - if (!_trust_content_header) && !content().empty()) { + if (!_trust_content_header && !content().empty()) { /* We just said that we don't trust the content's header */ examine_content (); } diff --git a/src/lib/imagemagick_encoder.cc b/src/lib/imagemagick_encoder.cc index 480dec8bc..4fa702369 100644 --- a/src/lib/imagemagick_encoder.cc +++ b/src/lib/imagemagick_encoder.cc @@ -38,6 +38,7 @@ using std::string; using std::ofstream; +using std::cout; using boost::shared_ptr; /** @param f Film that we are encoding. @@ -55,6 +56,8 @@ ImageMagickEncoder::do_process_video (shared_ptr image, shared_ptr scaled = image->scale_and_convert_to_rgb (_opt->out_size, _opt->padding, _film->scaler()); shared_ptr compact (new CompactImage (scaled)); + cout << "IME writes frame " << _video_frame << "\n"; + string tmp_file = _opt->frame_out_path (_video_frame, true); Magick::Image thumb (compact->size().width, compact->size().height, "RGB", MagickCore::CharPixel, compact->data()[0]); thumb.magick ("PNG"); diff --git a/src/lib/options.h b/src/lib/options.h index 29b3b71cd..2fc3e5599 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -104,9 +104,14 @@ public: boost::optional > audio_decode_range; /** Skip frames such that we don't decode any frame where (index % decode_video_skip) != 0; e.g. - * 1 for every frame, 2 for every other frame, etc. + * 1 for every frame, 2 for every other frame, etc. With the `precise' skip, we do it + * by running the decoder without seeking and throwing away frames that we don't want. */ - SourceFrame decode_video_skip; + boost::optional precise_decode_video_skip; + /** As for precise_decode_video_skip, except that it is achieved by skipping the decoder, so + * things are made less precise by the presence of keyframes and other complications. + */ + boost::optional rough_decode_video_skip; bool decode_audio; ///< true to decode audio, otherwise false bool decode_subtitles; diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index a7e79b05f..f764c65fb 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -49,7 +49,9 @@ using boost::dynamic_pointer_cast; * @param e Encoder to use. */ Transcoder::Transcoder (shared_ptr f, shared_ptr o, Job* j, shared_ptr e) - : _job (j) + : _film (f) + , _opt (o) + , _job (j) , _encoder (e) , _decoders (decoder_factory (f, o, j)) { @@ -90,6 +92,8 @@ void Transcoder::go () { _encoder->process_begin (); + SourceFrame s = 0; + try { bool done[2] = { false, false }; diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h index 4a9667b3c..43c70df00 100644 --- a/src/lib/transcoder.h +++ b/src/lib/transcoder.h @@ -54,6 +54,8 @@ public: } protected: + boost::shared_ptr _film; + boost::shared_ptr _opt; /** A Job that is running this Transcoder, or 0 */ Job* _job; /** The encoder that we will use */ diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 186e9c86b..b9a462801 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -155,7 +155,10 @@ checked_set (wxComboBox* widget, int value) void checked_set (wxComboBox* widget, string value) { - wxClientData* o = widget->GetClientObject (widget->GetSelection ()); + wxClientData* o = 0; + if (widget->GetSelection() != -1) { + o = widget->GetClientObject (widget->GetSelection ()); + } if (!o || string_client_data(o) != value) { for (unsigned int i = 0; i < widget->GetCount(); ++i) { -- cgit v1.2.3 From 3ce37f08e98b9c3a238fb1c9a6184fb7fd4e5667 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 16 Dec 2012 14:43:16 +0000 Subject: Revert "Skipping hacks." This reverts commit 89319eb1217c8caca80dc22ca770766f6d2f26c0. --- src/lib/encoder.cc | 5 ++ src/lib/ffmpeg_decoder.cc | 109 +++++++++++++++-------------------------- src/lib/ffmpeg_decoder.h | 3 -- src/lib/film.cc | 2 +- src/lib/imagemagick_encoder.cc | 3 -- src/lib/options.h | 9 +--- src/lib/transcoder.cc | 6 +-- src/lib/transcoder.h | 2 - src/wx/wx_util.cc | 5 +- 9 files changed, 49 insertions(+), 95 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index dfb154f72..17a6726a6 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -107,6 +107,11 @@ Encoder::frame_skipped () void Encoder::process_video (shared_ptr i, boost::shared_ptr s) { + if (_opt->decode_video_skip != 0 && (_video_frame % _opt->decode_video_skip) != 0) { + ++_video_frame; + return; + } + if (_opt->video_decode_range) { pair const r = _opt->video_decode_range.get(); if (_video_frame < r.first || _video_frame >= r.second) { diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 1e473b6a3..acaf149f4 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -265,10 +265,46 @@ FFmpegDecoder::pass () _film->log()->log (String::compose ("Used only %1 bytes of %2 in packet", r, _packet.size)); } - if (_opt->rough_decode_video_skip) { - rough_video_output (); + /* Where we are in the output, in seconds */ + double const out_pts_seconds = video_frame() / frames_per_second(); + + /* Where we are in the source, in seconds */ + double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) + * av_frame_get_best_effort_timestamp(_frame); + + _film->log()->log ( + String::compose ("Source video frame ready; source at %1, output at %2", source_pts_seconds, out_pts_seconds), + Log::VERBOSE + ); + + if (!_first_video) { + _first_video = source_pts_seconds; + } + + /* Difference between where we are and where we should be */ + double const delta = source_pts_seconds - _first_video.get() - out_pts_seconds; + double const one_frame = 1 / frames_per_second(); + + /* Insert frames if required to get out_pts_seconds up to pts_seconds */ + if (delta > one_frame) { + int const extra = rint (delta / one_frame); + for (int i = 0; i < extra; ++i) { + repeat_last_video (); + _film->log()->log ( + String::compose ( + "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)", + out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second() + ) + ); + } + } + + if (delta > -one_frame) { + /* Process this frame */ + filter_and_emit_video (_frame); } else { - precise_video_output (); + /* Otherwise we are omitting a frame to keep things right */ + _film->log()->log (String::compose ("Frame removed at %1s", out_pts_seconds)); } } @@ -601,70 +637,3 @@ FFmpegDecoder::length () const { return (double(_format_context->duration) / AV_TIME_BASE) * frames_per_second(); } - -void -FFmpegDecoder::precise_video_output () -{ - /* Where we are in the output, in seconds */ - double const out_pts_seconds = video_frame() / frames_per_second(); - - /* Where we are in the source, in seconds */ - double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) - * av_frame_get_best_effort_timestamp(_frame); - - _film->log()->log ( - String::compose ("Source video frame ready; source at %1, output at %2", source_pts_seconds, out_pts_seconds), - Log::VERBOSE - ); - - if (!_first_video) { - _first_video = source_pts_seconds; - } - - /* Difference between where we are and where we should be */ - double const delta = source_pts_seconds - _first_video.get() - out_pts_seconds; - double const one_frame = 1 / frames_per_second(); - - /* Insert frames if required to get out_pts_seconds up to pts_seconds */ - if (delta > one_frame) { - int const extra = rint (delta / one_frame); - for (int i = 0; i < extra; ++i) { - repeat_last_video (); - _film->log()->log ( - String::compose ( - "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)", - out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second() - ) - ); - } - } - - if (delta > -one_frame) { - /* Process this 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)); - } -} - -void -FFmpegDecoder::rough_video_output () -{ - /* Where we are in the source, in seconds */ - double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) - * av_frame_get_best_effort_timestamp(_frame); - - if (!_last_rough_output || _last_rough_output.get() != source_pts_seconds) { - filter_and_emit_video (_frame); - _last_rough_output = source_pts_seconds; - } - - int64_t const t = static_cast(f) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second()); - cout << "seek to " << t << " in stream tb\n"; - int const r = av_seek_frame (_format_context, _video_stream, t, 0); - avcodec_flush_buffers (_video_codec_context); - if (r < 0) { - cout << "seek to " << t << " failed.\n"; - } -} diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 141b40da0..1771551fc 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -105,8 +105,6 @@ private: AVSampleFormat audio_sample_format () const; int bytes_per_audio_sample () const; - void rough_video_output (); - void precise_video_output (); void filter_and_emit_video (AVFrame *); void setup_general (); @@ -135,7 +133,6 @@ private: boost::optional _first_video; boost::optional _first_audio; - boost::optional _last_rough_output; std::list > _filter_graphs; }; diff --git a/src/lib/film.cc b/src/lib/film.cc index ecf37f033..e2a4cbeda 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1003,7 +1003,7 @@ Film::set_trust_content_header (bool t) signal_changed (TRUST_CONTENT_HEADER); - if (!_trust_content_header && !content().empty()) { + if (!_trust_content_header) && !content().empty()) { /* We just said that we don't trust the content's header */ examine_content (); } diff --git a/src/lib/imagemagick_encoder.cc b/src/lib/imagemagick_encoder.cc index 4fa702369..480dec8bc 100644 --- a/src/lib/imagemagick_encoder.cc +++ b/src/lib/imagemagick_encoder.cc @@ -38,7 +38,6 @@ using std::string; using std::ofstream; -using std::cout; using boost::shared_ptr; /** @param f Film that we are encoding. @@ -56,8 +55,6 @@ ImageMagickEncoder::do_process_video (shared_ptr image, shared_ptr scaled = image->scale_and_convert_to_rgb (_opt->out_size, _opt->padding, _film->scaler()); shared_ptr compact (new CompactImage (scaled)); - cout << "IME writes frame " << _video_frame << "\n"; - string tmp_file = _opt->frame_out_path (_video_frame, true); Magick::Image thumb (compact->size().width, compact->size().height, "RGB", MagickCore::CharPixel, compact->data()[0]); thumb.magick ("PNG"); diff --git a/src/lib/options.h b/src/lib/options.h index 2fc3e5599..29b3b71cd 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -104,14 +104,9 @@ public: boost::optional > audio_decode_range; /** Skip frames such that we don't decode any frame where (index % decode_video_skip) != 0; e.g. - * 1 for every frame, 2 for every other frame, etc. With the `precise' skip, we do it - * by running the decoder without seeking and throwing away frames that we don't want. + * 1 for every frame, 2 for every other frame, etc. */ - boost::optional precise_decode_video_skip; - /** As for precise_decode_video_skip, except that it is achieved by skipping the decoder, so - * things are made less precise by the presence of keyframes and other complications. - */ - boost::optional rough_decode_video_skip; + SourceFrame decode_video_skip; bool decode_audio; ///< true to decode audio, otherwise false bool decode_subtitles; diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index f764c65fb..a7e79b05f 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -49,9 +49,7 @@ using boost::dynamic_pointer_cast; * @param e Encoder to use. */ Transcoder::Transcoder (shared_ptr f, shared_ptr o, Job* j, shared_ptr e) - : _film (f) - , _opt (o) - , _job (j) + : _job (j) , _encoder (e) , _decoders (decoder_factory (f, o, j)) { @@ -92,8 +90,6 @@ void Transcoder::go () { _encoder->process_begin (); - SourceFrame s = 0; - try { bool done[2] = { false, false }; diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h index 43c70df00..4a9667b3c 100644 --- a/src/lib/transcoder.h +++ b/src/lib/transcoder.h @@ -54,8 +54,6 @@ public: } protected: - boost::shared_ptr _film; - boost::shared_ptr _opt; /** A Job that is running this Transcoder, or 0 */ Job* _job; /** The encoder that we will use */ diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index b9a462801..186e9c86b 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -155,10 +155,7 @@ checked_set (wxComboBox* widget, int value) void checked_set (wxComboBox* widget, string value) { - wxClientData* o = 0; - if (widget->GetSelection() != -1) { - o = widget->GetClientObject (widget->GetSelection ()); - } + wxClientData* o = widget->GetClientObject (widget->GetSelection ()); if (!o || string_client_data(o) != value) { for (unsigned int i = 0; i < widget->GetCount(); ++i) { -- cgit v1.2.3