2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/examine_content_job.cc
21 * @brief A class to run through content at high speed to find its length.
24 #include <boost/filesystem.hpp>
25 #include "examine_content_job.h"
27 #include "decoder_factory.h"
29 #include "transcoder.h"
32 #include "video_decoder.h"
37 using boost::shared_ptr;
39 ExamineContentJob::ExamineContentJob (shared_ptr<Film> f, shared_ptr<Job> req)
45 ExamineContentJob::~ExamineContentJob ()
50 ExamineContentJob::name () const
52 if (_film->name().empty ()) {
53 return "Examine content";
56 return String::compose ("Examine content of %1", _film->name());
60 ExamineContentJob::run ()
62 /* Decode the content to get an accurate length */
64 /* We don't want to use any existing length here, as progress
67 _film->unset_length ();
69 shared_ptr<Options> o (new Options ("", "", ""));
70 o->out_size = Size (512, 512);
71 o->apply_crop = false;
72 o->decode_audio = false;
76 pair<shared_ptr<VideoDecoder>, shared_ptr<AudioDecoder> > decoders = decoder_factory (_film, o, this);
78 set_progress_unknown ();
79 while (!decoders.first->pass()) {
83 _film->set_length (decoders.first->video_frame());
85 _film->log()->log (String::compose ("Video length is %1 frames", _film->length()));
89 set_state (FINISHED_OK);