#include "options.h"
#include "decoder_factory.h"
#include "decoder.h"
-#include "imagemagick_encoder.h"
#include "transcoder.h"
#include "log.h"
#include "film.h"
o->apply_crop = false;
o->decode_audio = false;
- descend (0.5);
+ descend (1);
pair<shared_ptr<VideoDecoder>, shared_ptr<AudioDecoder> > decoders = decoder_factory (_film, o, this);
_film->log()->log (String::compose ("Video length is %1 frames", _film->length()));
- ascend ();
-
- /* Now make thumbnails for it */
-
- descend (0.5);
-
- try {
- o.reset (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_subtitles = true;
- shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (_film, o));
- Transcoder w (_film, o, this, e);
- w.go ();
-
- } catch (std::exception& e) {
-
- ascend ();
- set_progress (1);
- set_error (e.what ());
- set_state (FINISHED_ERROR);
- return;
-
- }
-
- string const tdir = _film->dir ("thumbs");
- vector<SourceFrame> thumbs;
-
- for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (tdir); i != boost::filesystem::directory_iterator(); ++i) {
-
- /* Aah, the sweet smell of progress */
-#if BOOST_FILESYSTEM_VERSION == 3
- string const l = boost::filesystem::path(*i).leaf().generic_string();
-#else
- string const l = i->leaf ();
-#endif
-
- size_t const d = l.find (".png");
- size_t const t = l.find (".tmp");
- if (d != string::npos && t == string::npos) {
- thumbs.push_back (atoi (l.substr (0, d).c_str()));
- }
- }
-
- sort (thumbs.begin(), thumbs.end());
- _film->set_thumbs (thumbs);
-
ascend ();
set_progress (1);
set_state (FINISHED_OK);
#include <boost/date_time.hpp>
#include "film.h"
#include "format.h"
-#include "imagemagick_encoder.h"
#include "job.h"
#include "filter.h"
#include "transcoder.h"
, _studio (o._studio)
, _facility (o._facility)
, _package_type (o._package_type)
- , _thumbs (o._thumbs)
, _size (o._size)
, _length (o._length)
, _content_digest (o._content_digest)
return;
}
- set_thumbs (vector<SourceFrame> ());
- boost::filesystem::remove_all (dir ("thumbs"));
-
- /* This call will recreate the directory */
- dir ("thumbs");
-
_examine_content_job.reset (new ExamineContentJob (shared_from_this(), shared_ptr<Job> ()));
_examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
JobManager::instance()->add (_examine_content_job);
return N;
}
-/** Return the filename of a subtitle image if one exists for a given thumb index.
- * @param Thumbnail index.
- * @return Position of the image within the source frame, and the image filename, if one exists.
- * Otherwise the filename will be empty.
- */
-pair<Position, string>
-Film::thumb_subtitle (int n) const
-{
- string sub_file = thumb_base(n) + ".sub";
- if (!boost::filesystem::exists (sub_file)) {
- return pair<Position, string> ();
- }
-
- pair<Position, string> sub;
-
- ifstream f (sub_file.c_str ());
- multimap<string, string> kv = read_key_value (f);
- for (map<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
- if (i->first == "x") {
- sub.first.x = lexical_cast<int> (i->second);
- } else if (i->first == "y") {
- sub.first.y = lexical_cast<int> (i->second);
- sub.second = String::compose ("%1.sub.png", thumb_base(n));
- }
- }
-
- return sub;
-}
-
/** Write state to our `metadata' file */
void
Film::write_metadata () const
f << "facility " << _facility << "\n";
f << "package_type " << _package_type << "\n";
- /* Cached stuff; this is information about our content; we could
- look it up each time, but that's slow.
- */
- for (vector<SourceFrame>::const_iterator i = _thumbs.begin(); i != _thumbs.end(); ++i) {
- f << "thumb " << *i << "\n";
- }
f << "width " << _size.width << "\n";
f << "height " << _size.height << "\n";
f << "length " << _length.get_value_or(0) << "\n";
boost::mutex::scoped_lock lm (_state_mutex);
_external_audio.clear ();
- _thumbs.clear ();
_content_audio_streams.clear ();
_subtitle_streams.clear ();
}
/* Cached stuff */
- if (k == "thumb") {
- int const n = atoi (v.c_str ());
- /* Only add it to the list if it still exists */
- if (boost::filesystem::exists (thumb_file_for_frame (n))) {
- _thumbs.push_back (n);
- }
- } else if (k == "width") {
+ if (k == "width") {
_size.width = atoi (v.c_str ());
} else if (k == "height") {
_size.height = atoi (v.c_str ());
_dirty = false;
}
-/** @param n A thumb index.
- * @return The path to the thumb's image file.
- */
-string
-Film::thumb_file (int n) const
-{
- return thumb_file_for_frame (thumb_frame (n));
-}
-
-/** @param n A frame index within the Film's source.
- * @return The path to the thumb's image file for this frame;
- * we assume that it exists.
- */
-string
-Film::thumb_file_for_frame (SourceFrame n) const
-{
- return thumb_base_for_frame(n) + ".png";
-}
-
-/** @param n Thumb index.
- * Must not be called with the _state_mutex locked.
- */
-string
-Film::thumb_base (int n) const
-{
- return thumb_base_for_frame (thumb_frame (n));
-}
-
-string
-Film::thumb_base_for_frame (SourceFrame n) const
-{
- stringstream s;
- s.width (8);
- s << setfill('0') << n;
-
- boost::filesystem::path p;
- p /= dir ("thumbs");
- p /= s.str ();
-
- return p.string ();
-}
-
-/** @param n A thumb index.
- * @return The frame within the Film's source that it is for.
- *
- * Must not be called with the _state_mutex locked.
- */
-SourceFrame
-Film::thumb_frame (int n) const
-{
- boost::mutex::scoped_lock lm (_state_mutex);
- assert (n < int (_thumbs.size ()));
- return _thumbs[n];
-}
-
Size
Film::cropped_size (Size s) const
{
signal_changed (DCI_METADATA);
}
-void
-Film::set_thumbs (vector<SourceFrame> t)
-{
- {
- boost::mutex::scoped_lock lm (_state_mutex);
- _thumbs = t;
- }
- signal_changed (THUMBS);
-}
-
void
Film::set_size (Size s)
{
std::string j2k_dir () const;
std::vector<std::string> audio_files () const;
- std::pair<Position, std::string> thumb_subtitle (int) const;
void examine_content ();
void send_dcp_to_tms ();
std::string content_path () const;
ContentType content_type () const;
- std::string thumb_file (int) const;
- std::string thumb_base (int) const;
- SourceFrame thumb_frame (int) const;
-
int target_audio_sample_rate () const;
void write_metadata () const;
SUBTITLE_OFFSET,
SUBTITLE_SCALE,
DCI_METADATA,
- THUMBS,
SIZE,
LENGTH,
CONTENT_AUDIO_STREAMS,
return _package_type;
}
- std::vector<SourceFrame> thumbs () const {
- boost::mutex::scoped_lock lm (_state_mutex);
- return _thumbs;
- }
-
Size size () const {
boost::mutex::scoped_lock lm (_state_mutex);
return _size;
void set_studio (std::string);
void set_facility (std::string);
void set_package_type (std::string);
- void set_thumbs (std::vector<SourceFrame>);
void set_size (Size);
void set_length (SourceFrame);
void unset_length ();
/** The date that we should use in a DCI name */
boost::gregorian::date _dci_date;
- std::string thumb_file_for_frame (SourceFrame) const;
- std::string thumb_base_for_frame (SourceFrame) const;
void signal_changed (Property);
void examine_content_finished ();
/* Data which are cached to speed things up */
- /** Vector of frame indices for each of our `thumbnails' */
- std::vector<SourceFrame> _thumbs;
/** Size, in pixels, of the source (ignoring cropping) */
Size _size;
/** Actual length of the source (in video frames) from examining it */
+++ /dev/null
-/*
- 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/imagemagick_encoder.cc
- * @brief An encoder that writes image files using ImageMagick (and does nothing with audio).
- */
-
-#include <stdexcept>
-#include <vector>
-#include <sstream>
-#include <iomanip>
-#include <iostream>
-#include <fstream>
-#include <boost/filesystem.hpp>
-#include <Magick++/Image.h>
-#include "imagemagick_encoder.h"
-#include "film.h"
-#include "options.h"
-#include "exceptions.h"
-#include "image.h"
-#include "subtitle.h"
-
-using std::string;
-using std::ofstream;
-using boost::shared_ptr;
-
-/** @param f Film that we are encoding.
- * @param o Options.
- */
-ImageMagickEncoder::ImageMagickEncoder (shared_ptr<const Film> f, shared_ptr<const Options> o)
- : Encoder (f, o)
-{
-
-}
-
-void
-ImageMagickEncoder::do_process_video (shared_ptr<Image> image, shared_ptr<Subtitle> sub)
-{
- shared_ptr<Image> scaled = image->scale_and_convert_to_rgb (_opt->out_size, _opt->padding, _film->scaler());
- shared_ptr<Image> compact (new CompactImage (scaled));
-
- 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");
- thumb.write (tmp_file);
- boost::filesystem::rename (tmp_file, _opt->frame_out_path (_video_frame, false));
-
- if (sub) {
- float const x_scale = float (_opt->out_size.width) / _film->size().width;
- float const y_scale = float (_opt->out_size.height) / _film->size().height;
-
- string tmp_metadata_file = _opt->frame_out_path (_video_frame, false, ".sub");
- ofstream metadata (tmp_metadata_file.c_str ());
-
- Size new_size = sub->image()->size ();
- new_size.width *= x_scale;
- new_size.height *= y_scale;
- shared_ptr<Image> scaled = sub->image()->scale (new_size, _film->scaler());
- shared_ptr<Image> compact (new CompactImage (scaled));
-
- string tmp_sub_file = _opt->frame_out_path (_video_frame, true, ".sub.png");
- Magick::Image sub_thumb (compact->size().width, compact->size().height, "RGBA", MagickCore::CharPixel, compact->data()[0]);
- sub_thumb.magick ("PNG");
- sub_thumb.write (tmp_sub_file);
- boost::filesystem::rename (tmp_sub_file, _opt->frame_out_path (_video_frame, false, ".sub.png"));
-
- metadata << "x " << sub->position().x << "\n"
- << "y " << sub->position().y << "\n";
-
- metadata.close ();
- boost::filesystem::rename (tmp_metadata_file, _opt->frame_out_path (_video_frame, false, ".sub"));
- }
-
- frame_done ();
-}
+++ /dev/null
-/*
- 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/imagemagick_encoder.h
- * @brief An encoder that writes image files using ImageMagick (and does nothing with audio).
- */
-
-#include <string>
-#include <sndfile.h>
-#include "encoder.h"
-
-class FilmState;
-class Log;
-
-/** @class ImageMagickEncoder
- * @brief An encoder that writes image files using ImageMagick files (and does nothing with audio).
- */
-class ImageMagickEncoder : public Encoder
-{
-public:
- ImageMagickEncoder (boost::shared_ptr<const Film> f, boost::shared_ptr<const Options> o);
-
-private:
- void do_process_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
- void do_process_audio (boost::shared_ptr<AudioBuffers>) {}
-};
gain.cc
image.cc
imagemagick_decoder.cc
- imagemagick_encoder.cc
j2k_still_encoder.cc
j2k_wav_encoder.cc
job.cc
checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
_dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
break;
- case Film::THUMBS:
- break;
case Film::DCP_AB:
checked_set (_dcp_ab, _film->dcp_ab ());
break;
{
shared_ptr<Film> f = new_test_film ("paths_test");
f->set_directory ("build/test/a/b/c/d/e");
- vector<SourceFrame> thumbs;
- thumbs.push_back (42);
- f->set_thumbs (thumbs);
- BOOST_CHECK_EQUAL (f->thumb_file (0), "build/test/a/b/c/d/e/thumbs/00000042.png");
f->_content = "/foo/bar/baz";
BOOST_CHECK_EQUAL (f->content_path(), "/foo/bar/baz");