Move things round a bit.
[dcpomatic.git] / src / lib / j2k_still_encoder.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  src/j2k_wav_encoder.cc
21  *  @brief An encoder which writes JPEG2000 and WAV files.
22  */
23
24 #include <sstream>
25 #include <stdexcept>
26 #include <iomanip>
27 #include <iostream>
28 #include <boost/filesystem.hpp>
29 #include <sndfile.h>
30 #include <openjpeg.h>
31 #include "j2k_still_encoder.h"
32 #include "config.h"
33 #include "film_state.h"
34 #include "options.h"
35 #include "exceptions.h"
36 #include "dcp_video_frame.h"
37 #include "filter.h"
38 #include "log.h"
39 #include "imagemagick_decoder.h"
40
41 using namespace std;
42 using namespace boost;
43
44 J2KStillEncoder::J2KStillEncoder (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l)
45         : Encoder (s, o, l)
46 {
47         
48 }
49
50 void
51 J2KStillEncoder::process_video (shared_ptr<Image> yuv, int frame)
52 {
53         pair<string, string> const s = Filter::ffmpeg_strings (_fs->filters);
54         DCPVideoFrame* f = new DCPVideoFrame (
55                 yuv, _opt->out_size, _opt->padding, _fs->scaler, 0, _fs->frames_per_second, s.second,
56                 Config::instance()->colour_lut_index(), Config::instance()->j2k_bandwidth(),
57                 _log
58                 );
59
60         if (!boost::filesystem::exists (_opt->frame_out_path (1, false))) {
61                 boost::shared_ptr<EncodedData> e = f->encode_locally ();
62                 e->write (_opt, 1);
63         }
64
65         string const real = _opt->frame_out_path (1, false);
66         for (int i = 2; i <= (_fs->still_duration * ImageMagickDecoder::static_frames_per_second()); ++i) {
67                 if (!boost::filesystem::exists (_opt->frame_out_path (i, false))) {
68                         string const link = _opt->frame_out_path (i, false);
69                         symlink (real.c_str(), link.c_str());
70                 }
71                 frame_done ();
72         }
73 }