diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-21 13:09:10 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-21 13:09:10 +0100 |
| commit | 6b368187e7bc16cbe0e83858f35990e536c5ccc8 (patch) | |
| tree | a7ee36003c7974c05a3555dc2a1cbd06dbca13ad /src/lib | |
| parent | 5b17eb3a0b0f95417c210ac3f7c3b66b5eac483c (diff) | |
Partial merge of examine content and thumbnail jobs.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/examine_content_job.cc | 42 | ||||
| -rw-r--r-- | src/lib/film.cc | 75 | ||||
| -rw-r--r-- | src/lib/film.h | 9 | ||||
| -rw-r--r-- | src/lib/film_state.cc | 3 | ||||
| -rw-r--r-- | src/lib/film_state.h | 2 | ||||
| -rw-r--r-- | src/lib/thumbs_job.cc | 66 | ||||
| -rw-r--r-- | src/lib/thumbs_job.h | 37 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
9 files changed, 80 insertions, 157 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index d78089265..c398c53a0 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -166,7 +166,7 @@ Decoder::pass () _have_setup_video_filters = true; } - if (_video_frame >= _fs->dcp_length()) { + if (!_ignore_length && _video_frame >= _fs->dcp_length()) { return true; } diff --git a/src/lib/examine_content_job.cc b/src/lib/examine_content_job.cc index fd574e2d0..5800c6f24 100644 --- a/src/lib/examine_content_job.cc +++ b/src/lib/examine_content_job.cc @@ -26,6 +26,8 @@ #include "film_state.h" #include "decoder_factory.h" #include "decoder.h" +#include "imagemagick_encoder.h" +#include "transcoder.h" using namespace std; using namespace boost; @@ -49,13 +51,49 @@ ExamineContentJob::name () const void ExamineContentJob::run () { + shared_ptr<FilmState> fs = _fs->state_copy (); + + /* Decode the content to get an accurate length */ + shared_ptr<Options> o (new Options ("", "", "")); o->out_size = Size (512, 512); o->apply_crop = false; - _decoder = decoder_factory (_fs, o, this, _log, true, true); + descend (0.5); + + _decoder = decoder_factory (fs, o, this, _log, true, true); _decoder->go (); - + fs->set_length (last_video_frame ()); + + ascend (); + + /* Now make thumbnails for it */ + + descend (0.5); + + try { + o.reset (new Options (fs->dir ("thumbs"), ".png", "")); + o->out_size = fs->size (); + o->apply_crop = false; + o->decode_audio = false; + o->decode_video_frequency = 128; + o->decode_subtitles = true; + shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (fs, o, _log)); + Transcoder w (fs, o, this, _log, e); + w.go (); + set_progress (1); + set_state (FINISHED_OK); + + } catch (std::exception& e) { + + ascend (); + set_progress (1); + set_error (e.what ()); + set_state (FINISHED_ERROR); + + } + + ascend (); set_progress (1); set_state (FINISHED_OK); } diff --git a/src/lib/film.cc b/src/lib/film.cc index 1f511add7..74e5d0bb2 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -103,47 +103,6 @@ Film::~Film () delete _log; } -/** The pre-processing GUI part of a thumbs update. - * Must be called from the GUI thread. - */ -void -Film::update_thumbs_pre_gui () -{ - set_thumbs (vector<int> ()); - filesystem::remove_all (dir ("thumbs")); - - /* This call will recreate the directory */ - dir ("thumbs"); -} - -/** The post-processing GUI part of a thumbs update. - * Must be called from the GUI thread. - */ -void -Film::update_thumbs_post_gui () -{ - string const tdir = dir ("thumbs"); - vector<int> thumbs; - - for (filesystem::directory_iterator i = filesystem::directory_iterator (tdir); i != filesystem::directory_iterator(); ++i) { - - /* Aah, the sweet smell of progress */ -#if BOOST_FILESYSTEM_VERSION == 3 - string const l = filesystem::path(*i).leaf().generic_string(); -#else - string const l = i->leaf (); -#endif - - size_t const d = l.find (".png"); - if (d != string::npos) { - thumbs.push_back (atoi (l.substr (0, d).c_str())); - } - } - - sort (thumbs.begin(), thumbs.end()); - set_thumbs (thumbs); -} - /** @return The path to the directory to write JPEG2000 files to */ string Film::j2k_dir () const @@ -281,6 +240,12 @@ Film::examine_content () if (_examine_content_job) { return; } + + set_thumbs (vector<int> ()); + filesystem::remove_all (dir ("thumbs")); + + /* This call will recreate the directory */ + dir ("thumbs"); _examine_content_job.reset (new ExamineContentJob (state_copy (), log(), shared_ptr<Job> ())); _examine_content_job->Finished.connect (sigc::mem_fun (*this, &Film::examine_content_post_gui)); @@ -292,6 +257,27 @@ Film::examine_content_post_gui () { set_length (_examine_content_job->last_video_frame ()); _examine_content_job.reset (); + + string const tdir = dir ("thumbs"); + vector<int> thumbs; + + for (filesystem::directory_iterator i = filesystem::directory_iterator (tdir); i != filesystem::directory_iterator(); ++i) { + + /* Aah, the sweet smell of progress */ +#if BOOST_FILESYSTEM_VERSION == 3 + string const l = filesystem::path(*i).leaf().generic_string(); +#else + string const l = i->leaf (); +#endif + + size_t const d = l.find (".png"); + if (d != string::npos) { + thumbs.push_back (atoi (l.substr (0, d).c_str())); + } + } + + sort (thumbs.begin(), thumbs.end()); + set_thumbs (thumbs); } @@ -370,3 +356,10 @@ Film::thumb_subtitle (int n) const return sub; } + +void +Film::set_content (string c) +{ + FilmState::set_content (c); + examine_content (); +} diff --git a/src/lib/film.h b/src/lib/film.h index d5c7420f8..59589b325 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -55,11 +55,7 @@ public: ~Film (); std::string j2k_dir () const; - std::vector<std::string> audio_files () const; - - void update_thumbs_pre_gui (); - void update_thumbs_post_gui (); std::pair<Position, std::string> thumb_subtitle (int) const; void copy_from_dvd_post_gui (); @@ -79,7 +75,10 @@ public: int encoded_frames () const; -private: + void set_content (std::string); + +private: + /** Log to write to */ Log* _log; diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc index 09c5e3efd..6ce88f2bb 100644 --- a/src/lib/film_state.cc +++ b/src/lib/film_state.cc @@ -529,7 +529,6 @@ FilmState::set_content (string c) shared_ptr<Decoder> d = decoder_factory (s, o, 0, 0); set_size (d->native_size ()); - set_length (d->length_in_frames ()); set_frames_per_second (d->frames_per_second ()); set_audio_sample_rate (d->audio_sample_rate ()); set_has_subtitles (d->has_subtitles ()); @@ -834,5 +833,3 @@ FilmState::audio_channels () const return _audio_streams[_audio_stream].channels (); } - - diff --git a/src/lib/film_state.h b/src/lib/film_state.h index c76e845f3..43df2ba8f 100644 --- a/src/lib/film_state.h +++ b/src/lib/film_state.h @@ -302,7 +302,7 @@ public: void set_directory (std::string); void set_name (std::string); void set_use_dci_name (bool); - void set_content (std::string); + virtual void set_content (std::string); void set_dcp_content_type (DCPContentType const *); void set_format (Format const *); void set_crop (Crop); diff --git a/src/lib/thumbs_job.cc b/src/lib/thumbs_job.cc deleted file mode 100644 index 845dc9675..000000000 --- a/src/lib/thumbs_job.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/thumbs_job.cc - * @brief A job to create thumbnails. - */ - -#include <exception> -#include "thumbs_job.h" -#include "film_state.h" -#include "imagemagick_encoder.h" -#include "transcoder.h" -#include "options.h" - -using namespace std; -using namespace boost; - -/** @param s FilmState to use. - * @param o Options. - * @param l A log that we can write to. - */ -ThumbsJob::ThumbsJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l, shared_ptr<Job> req) - : Job (s, o, l, req) -{ - -} - -string -ThumbsJob::name () const -{ - return String::compose ("Update thumbs for %1", _fs->name()); -} - -void -ThumbsJob::run () -{ - try { - shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (_fs, _opt, _log)); - Transcoder w (_fs, _opt, this, _log, e); - w.go (); - set_progress (1); - set_state (FINISHED_OK); - - } catch (std::exception& e) { - - set_progress (1); - set_error (e.what ()); - set_state (FINISHED_ERROR); - } -} diff --git a/src/lib/thumbs_job.h b/src/lib/thumbs_job.h deleted file mode 100644 index f7e30d576..000000000 --- a/src/lib/thumbs_job.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/thumbs_job.h - * @brief A job to create thumbnails. - */ - -#include "job.h" - -class FilmState; - -/** @class ThumbsJob - * @brief A job to create thumbnails (single frames of the film spaced out throughout the film). - */ -class ThumbsJob : public Job -{ -public: - ThumbsJob (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l, boost::shared_ptr<Job> req); - std::string name () const; - void run (); -}; diff --git a/src/lib/wscript b/src/lib/wscript index 6ce216d81..04db716a4 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -45,7 +45,6 @@ def build(bld): sound_processor.cc stream.cc subtitle.cc - thumbs_job.cc tiff_decoder.cc timer.cc transcode_job.cc |
