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"
39 using boost::shared_ptr;
41 ExamineContentJob::ExamineContentJob (shared_ptr<Film> f)
47 ExamineContentJob::~ExamineContentJob ()
52 ExamineContentJob::name () const
54 if (_film->name().empty ()) {
55 return _("Examine content");
58 return String::compose (_("Examine content of %1"), _film->name());
62 ExamineContentJob::run ()
65 _film->set_content_digest (md5_digest (_film->content_path ()));
70 /* Set the film's length to either
71 a) a length judged by running through the content or
72 b) the length from a decoder's header.
74 if (!_film->trust_content_header()) {
75 /* Decode the content to get an accurate length */
77 /* We don't want to use any existing length here, as progress
80 _film->unset_length ();
81 _film->set_crop (Crop ());
84 o.decode_audio = false;
86 Decoders decoders = decoder_factory (_film, o);
88 set_progress_unknown ();
89 while (!decoders.video->pass()) {
93 _film->set_length (decoders.video->video_frame());
95 _film->log()->log (String::compose (N_("Video length examined as %1 frames"), _film->length().get()));
99 /* Get a quick decoder to get the content's length from its header */
101 Decoders d = decoder_factory (_film, DecodeOptions());
102 _film->set_length (d.video->length());
104 _film->log()->log (String::compose (N_("Video length obtained from header as %1 frames"), _film->length().get()));
109 set_state (FINISHED_OK);