From 8042a85601d75d8a69bf0a0d1b00fcdbced252b4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 22:30:35 +0100 Subject: Create film directory in constructor. --- src/lib/film.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/film.cc b/src/lib/film.cc index 2db03f6a6..20edacf59 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -85,8 +85,12 @@ Film::Film (string d, bool must_exist) _state.directory = result.string (); - if (must_exist && !filesystem::exists (_state.directory)) { - throw OpenFileError (_state.directory); + if (!filesystem::exists (_state.directory)) { + if (must_exist) { + throw OpenFileError (_state.directory); + } else { + filesystem::create_directory (_state.directory); + } } read_metadata (); -- cgit v1.2.3 From d9fd19336dcb823a5f0199adf41b37eb8d177f4d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 22:31:53 +0100 Subject: Pick up last few frames properly when decoding. --- src/lib/ffmpeg_decoder.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 3471ffaab..1096bb253 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -161,11 +161,39 @@ FFmpegDecoder::do_pass () { int r = av_read_frame (_format_context, &_packet); if (r < 0) { + if (r != AVERROR_EOF) { + throw DecodeError ("error on av_read_frame"); + } + + /* Get any remaining frames */ + + _packet.data = 0; + _packet.size = 0; + + int frame_finished; + + if (_opt->decode_video) { + while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { + process_video (_frame); + } + } + + if (_audio_stream >= 0 && _opt->decode_audio) { + while (avcodec_decode_audio4 (_audio_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { + int const data_size = av_samples_get_buffer_size ( + 0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1 + ); + + assert (_audio_codec_context->channels == _fs->audio_channels); + process_audio (_frame->data[0], data_size); + } + } + return true; } if (_packet.stream_index == _video_stream && _opt->decode_video) { - + int frame_finished; if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { process_video (_frame); -- cgit v1.2.3 From bed01a8e72f31e73ea8f206f9b18d5910416e0c2 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 22:42:49 +0100 Subject: Simple test to make sure a couple of simple make DCP jobs complete. --- src/lib/job_manager.cc | 14 ++++++++++++++ src/lib/job_manager.h | 1 + test/test.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) (limited to 'src') diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc index a166b5924..76fcc6c5d 100644 --- a/src/lib/job_manager.cc +++ b/src/lib/job_manager.cc @@ -73,6 +73,20 @@ JobManager::work_to_do () const return i != _jobs.end (); } +bool +JobManager::errors () const +{ + boost::mutex::scoped_lock lm (_mutex); + for (list >::const_iterator i = _jobs.begin(); i != _jobs.end(); ++i) { + if ((*i)->finished_in_error ()) { + return true; + } + } + + return false; +} + + void JobManager::scheduler () { diff --git a/src/lib/job_manager.h b/src/lib/job_manager.h index d1d33cfc2..8b79fd67d 100644 --- a/src/lib/job_manager.h +++ b/src/lib/job_manager.h @@ -41,6 +41,7 @@ public: void add_after (boost::shared_ptr after, boost::shared_ptr j); std::list > get () const; bool work_to_do () const; + bool errors () const; static JobManager* instance (); diff --git a/test/test.cc b/test/test.cc index 638d526e0..99781d1a2 100644 --- a/test/test.cc +++ b/test/test.cc @@ -315,3 +315,50 @@ BOOST_AUTO_TEST_CASE (client_server_test) (*i)->join (); } } + +BOOST_AUTO_TEST_CASE (make_dcp_test) +{ + string const test_film = "build/test/film2"; + + if (boost::filesystem::exists (test_film)) { + boost::filesystem::remove_all (test_film); + } + + Film film (test_film, false); + film.set_name ("test_film"); + film.set_content ("../../../test/test.mp4"); + film.examine_content (); + film.set_format (Format::from_ratio (185)); + film.set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + film.make_dcp (true); + + while (JobManager::instance()->work_to_do ()) { + sleep (1); + } + + BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false); +} + +BOOST_AUTO_TEST_CASE (make_dcp_with_range_test) +{ + string const test_film = "build/test/film3"; + + if (boost::filesystem::exists (test_film)) { + boost::filesystem::remove_all (test_film); + } + + Film film (test_film, false); + film.set_name ("test_film"); + film.set_content ("../../../test/test.mp4"); + film.examine_content (); + film.set_format (Format::from_ratio (185)); + film.set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + film.set_dcp_frames (42); + film.make_dcp (true); + + while (JobManager::instance()->work_to_do ()) { + sleep (1); + } + + BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false); +} -- cgit v1.2.3 From 97675be04d4a87e00c99733ee7b904ccbe632994 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 22:51:06 +0100 Subject: Fix up some bugs when using limited DCP range (reported by Wolfgang Woehl). --- ChangeLog | 5 +++++ src/lib/check_hashes_job.cc | 4 +++- src/lib/film_state.cc | 12 ++++++++++++ src/lib/film_state.h | 2 ++ src/lib/transcode_job.cc | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/ChangeLog b/ChangeLog index d34b781b6..58876926e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-10-07 Carl Hetherington + + * Fix up some bugs when using limited DCP + range (reported by Wolfgang Woehl). + 2012-10-02 Carl Hetherington * Version 0.54 released. diff --git a/src/lib/check_hashes_job.cc b/src/lib/check_hashes_job.cc index cf269564a..f60a2d40d 100644 --- a/src/lib/check_hashes_job.cc +++ b/src/lib/check_hashes_job.cc @@ -48,8 +48,10 @@ void CheckHashesJob::run () { _bad = 0; + + int const N = _fs->dcp_length (); - for (int i = 0; i < _fs->length; ++i) { + for (int i = 0; i < N; ++i) { string const j2k_file = _opt->frame_out_path (i, false); string const hash_file = j2k_file + ".md5"; diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc index d7d9a1462..3cd7091ca 100644 --- a/src/lib/film_state.cc +++ b/src/lib/film_state.cc @@ -299,3 +299,15 @@ FilmState::target_sample_rate () const return rint (t); } + +int +FilmState::dcp_length () const +{ + if (dcp_frames) { + return dcp_frames; + } + + return length; +} + + diff --git a/src/lib/film_state.h b/src/lib/film_state.h index 8dc0ce11b..16a1b0508 100644 --- a/src/lib/film_state.h +++ b/src/lib/film_state.h @@ -87,6 +87,8 @@ public: Size cropped_size (Size) const; + int dcp_length () const; + /** Complete path to directory containing the film metadata; must not be relative. */ diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index e79be09fe..e1ba82359 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -107,5 +107,5 @@ TranscodeJob::remaining_time () const return 0; } - return ((_fs->length - _encoder->last_frame()) / fps); + return ((_fs->dcp_length() - _encoder->last_frame()) / fps); } -- cgit v1.2.3 From 3841160c61398e7bb70429040530969a3f0a3440 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 23:03:44 +0100 Subject: Fix comment. --- src/lib/j2k_still_encoder.cc | 4 ++-- src/lib/j2k_still_encoder.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/j2k_still_encoder.cc b/src/lib/j2k_still_encoder.cc index 8f3339a0a..d218d08fe 100644 --- a/src/lib/j2k_still_encoder.cc +++ b/src/lib/j2k_still_encoder.cc @@ -17,8 +17,8 @@ */ -/** @file src/j2k_wav_encoder.cc - * @brief An encoder which writes JPEG2000 and WAV files. +/** @file src/j2k_still_encoder.cc + * @brief An encoder which writes JPEG2000 files for a single still source image. */ #include diff --git a/src/lib/j2k_still_encoder.h b/src/lib/j2k_still_encoder.h index 755c68877..7a03e1195 100644 --- a/src/lib/j2k_still_encoder.h +++ b/src/lib/j2k_still_encoder.h @@ -17,8 +17,8 @@ */ -/** @file src/j2k_wav_encoder.h - * @brief An encoder which writes JPEG2000 and WAV files. +/** @file src/j2k_still_encoder.h + * @brief An encoder which writes JPEG2000 files for a single still source image. */ #include -- cgit v1.2.3 From 87a3395fb8c546f7b71f36f5b16739486699493e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 23:09:56 +0100 Subject: Fix comment. --- src/lib/decoder_factory.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/decoder_factory.cc b/src/lib/decoder_factory.cc index 6826724af..c03912094 100644 --- a/src/lib/decoder_factory.cc +++ b/src/lib/decoder_factory.cc @@ -42,7 +42,7 @@ decoder_factory ( if (fs->content_type() == STILL) { /* Always ignore length of decodes of stills, since the decoder finishes very quickly - and its the encoder that takes the time. + and it's the encoder that takes the time. */ return shared_ptr (new ImageMagickDecoder (fs, o, j, l, minimal, true)); } -- cgit v1.2.3 From 7c798f9e215282afb078da53b1d41d4c99e11f5d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 8 Oct 2012 00:08:33 +0100 Subject: Split Format into Fixed and Variable so that sources can be unstretched. --- src/lib/film.cc | 4 +- src/lib/format.cc | 109 +++++++++++++++++++++++++++++--------------------- src/lib/format.h | 69 +++++++++++++++++++++++--------- src/lib/image.cc | 2 +- src/wx/film_viewer.cc | 2 +- test/test.cc | 8 ++-- 6 files changed, 121 insertions(+), 73 deletions(-) (limited to 'src') diff --git a/src/lib/film.cc b/src/lib/film.cc index 20edacf59..330ae9e5d 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -534,8 +534,8 @@ Film::make_dcp (bool transcode, int freq) } o->decode_video_frequency = freq; - o->padding = format()->dcp_padding (); - o->ratio = format()->ratio_as_float (); + o->padding = format()->dcp_padding (this); + o->ratio = format()->ratio_as_float (this); if (transcode) { if (_state.dcp_ab) { diff --git a/src/lib/format.cc b/src/lib/format.cc index e689aa05d..115e03691 100644 --- a/src/lib/format.cc +++ b/src/lib/format.cc @@ -28,28 +28,15 @@ #include #include #include "format.h" +#include "film.h" using namespace std; vector Format::_formats; -/** @param r Ratio multiplied by 100 (e.g. 185) - * @param dcp Size (in pixels) of the images that we should put in a DCP. - * @param id ID (e.g. 185) - * @param n Nick name (e.g. Flat) - */ -Format::Format (int r, Size dcp, string id, string n) - : _ratio (r) - , _dcp_size (dcp) - , _id (id) - , _nickname (n) -{ - -} - /** @return A name to be presented to the user */ string -Format::name () const +FixedFormat::name () const { stringstream s; if (!_nickname.empty ()) { @@ -76,34 +63,18 @@ Format::as_metadata () const void Format::setup_formats () { - _formats.push_back (new Format (119, Size (1285, 1080), "119", "1.19")); - _formats.push_back (new Format (133, Size (1436, 1080), "133", "1.33")); - _formats.push_back (new Format (138, Size (1485, 1080), "138", "1.375")); - _formats.push_back (new Format (133, Size (1998, 1080), "133-in-flat", "4:3 within Flat")); - _formats.push_back (new Format (137, Size (1480, 1080), "137", "Academy")); - _formats.push_back (new Format (166, Size (1793, 1080), "166", "1.66")); - _formats.push_back (new Format (166, Size (1998, 1080), "166-in-flat", "1.66 within Flat")); - _formats.push_back (new Format (178, Size (1998, 1080), "178-in-flat", "16:9 within Flat")); - _formats.push_back (new Format (185, Size (1998, 1080), "185", "Flat")); - _formats.push_back (new Format (239, Size (2048, 858), "239", "Scope")); -} - -/** @param r Ratio multiplied by 100. - * @return Matching Format, or 0. - */ -Format const * -Format::from_ratio (int r) -{ - vector::iterator i = _formats.begin (); - while (i != _formats.end() && (*i)->ratio_as_integer() != r) { - ++i; - } - - if (i == _formats.end ()) { - return 0; - } - - return *i; + _formats.push_back (new FixedFormat (119, Size (1285, 1080), "119", "1.19")); + _formats.push_back (new FixedFormat (133, Size (1436, 1080), "133", "1.33")); + _formats.push_back (new FixedFormat (138, Size (1485, 1080), "138", "1.375")); + _formats.push_back (new FixedFormat (133, Size (1998, 1080), "133-in-flat", "4:3 within Flat")); + _formats.push_back (new FixedFormat (137, Size (1480, 1080), "137", "Academy")); + _formats.push_back (new FixedFormat (166, Size (1793, 1080), "166", "1.66")); + _formats.push_back (new FixedFormat (166, Size (1998, 1080), "166-in-flat", "1.66 within Flat")); + _formats.push_back (new FixedFormat (178, Size (1998, 1080), "178-in-flat", "16:9 within Flat")); + _formats.push_back (new FixedFormat (185, Size (1998, 1080), "185", "Flat")); + _formats.push_back (new FixedFormat (239, Size (2048, 858), "239", "Scope")); + _formats.push_back (new VariableFormat (Size (1998, 1080), "var-185", "Flat")); + _formats.push_back (new VariableFormat (Size (2048, 858), "var-239", "Scope")); } /** @param n Nickname. @@ -187,10 +158,22 @@ Format::all () return _formats; } +/** @param r Ratio multiplied by 100 (e.g. 185) + * @param dcp Size (in pixels) of the images that we should put in a DCP. + * @param id ID (e.g. 185) + * @param n Nick name (e.g. Flat) + */ +FixedFormat::FixedFormat (int r, Size dcp, string id, string n) + : Format (dcp, id, n) + , _ratio (r) +{ + +} + int -Format::dcp_padding () const +Format::dcp_padding (Film const * f) const { - int p = rint ((_dcp_size.width - (_dcp_size.height * _ratio / 100.0)) / 2.0); + int p = rint ((_dcp_size.width - (_dcp_size.height * ratio_as_integer(f) / 100.0)) / 2.0); /* This comes out -ve for Scope; bodge it */ if (p < 0) { @@ -199,3 +182,39 @@ Format::dcp_padding () const return p; } + +VariableFormat::VariableFormat (Size dcp, string id, string n) + : Format (dcp, id, n) +{ + +} + +int +VariableFormat::ratio_as_integer (Film const * f) const +{ + return rint (ratio_as_float (f) * 100); +} + +float +VariableFormat::ratio_as_float (Film const * f) const +{ + return float (f->size().width) / f->size().height; +} + +/** @return A name to be presented to the user */ +string +VariableFormat::name () const +{ + stringstream s; + if (!_nickname.empty ()) { + s << _nickname << " ("; + } + + s << "without stretching"; + + if (!_nickname.empty ()) { + s << ")"; + } + + return s.str (); +} diff --git a/src/lib/format.h b/src/lib/format.h index 4b727b2e3..6172dc57d 100644 --- a/src/lib/format.h +++ b/src/lib/format.h @@ -18,7 +18,7 @@ */ /** @file src/format.h - * @brief Class to describe a format (aspect ratio) that a Film should + * @brief Classes to describe a format (aspect ratio) that a Film should * be shown in. */ @@ -26,26 +26,26 @@ #include #include "util.h" -/** @class Format - * @brief Class to describe a format (aspect ratio) that a Film should - * be shown in. - */ +class Film; + class Format { public: - Format (int, Size, std::string, std::string); + Format (Size dcp, std::string id, std::string n) + : _dcp_size (dcp) + , _id (id) + , _nickname (n) + {} /** @return the aspect ratio multiplied by 100 * (e.g. 239 for Cinemascope 2.39:1) */ - int ratio_as_integer () const { - return _ratio; - } + virtual int ratio_as_integer (Film const * f) const = 0; /** @return the ratio as a floating point number */ - float ratio_as_float () const { - return _ratio / 100.0; - } + virtual float ratio_as_float (Film const * f) const = 0; + + int dcp_padding (Film const * f) const; /** @return size in pixels of the images that we should * put in a DCP for this ratio. This size will not correspond @@ -60,7 +60,7 @@ public: } /** @return Full name to present to the user */ - std::string name () const; + virtual std::string name () const = 0; /** @return Nickname (e.g. Flat, Scope) */ std::string nickname () const { @@ -69,9 +69,6 @@ public: std::string as_metadata () const; - int dcp_padding () const; - - static Format const * from_ratio (int); static Format const * from_nickname (std::string n); static Format const * from_metadata (std::string m); static Format const * from_index (int i); @@ -79,11 +76,8 @@ public: static int as_index (Format const * f); static std::vector all (); static void setup_formats (); - -private: - /** Ratio expressed as the actual ratio multiplied by 100 */ - int _ratio; +protected: /** Size in pixels of the images that we should * put in a DCP for this ratio. This size will not correspond * to the ratio when we are doing things like 16:9 in a Flat frame. @@ -94,8 +88,43 @@ private: /** nickname (e.g. Flat, Scope) */ std::string _nickname; +private: /** all available formats */ static std::vector _formats; }; +/** @class FixedFormat + * @brief Class to describe a format whose ratio is fixed regardless + * of source size. + */ +class FixedFormat : public Format +{ +public: + FixedFormat (int, Size, std::string, std::string); + + int ratio_as_integer (Film const *) const { + return _ratio; + } + + float ratio_as_float (Film const *) const { + return _ratio / 100.0; + } + + std::string name () const; +private: + + /** Ratio expressed as the actual ratio multiplied by 100 */ + int _ratio; +}; + +class VariableFormat : public Format +{ +public: + VariableFormat (Size, std::string, std::string); + + int ratio_as_integer (Film const * f) const; + float ratio_as_float (Film const * f) const; + + std::string name () const; +}; diff --git a/src/lib/image.cc b/src/lib/image.cc index 620e71aa7..2df7636af 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -94,7 +94,7 @@ Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scal content_size.width -= (padding * 2); shared_ptr rgb (new RGBFrameImage (content_size)); - + struct SwsContext* scale_context = sws_getContext ( size().width, size().height, pixel_format(), content_size.width, content_size.height, PIX_FMT_RGB24, diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index e647a5886..3c7d76bce 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -131,7 +131,7 @@ private: int vw, vh; GetSize (&vw, &vh); - float const target = _film->format() ? _film->format()->ratio_as_float () : 1.78; + float const target = _film->format() ? _film->format()->ratio_as_float (_film) : 1.78; _cropped_image = _image->GetSubImage ( wxRect ( diff --git a/test/test.cc b/test/test.cc index 99781d1a2..ebee50ac0 100644 --- a/test/test.cc +++ b/test/test.cc @@ -104,11 +104,11 @@ BOOST_AUTO_TEST_CASE (format_test) Format const * f = Format::from_nickname ("Flat"); BOOST_CHECK (f); - BOOST_CHECK_EQUAL (f->ratio_as_integer(), 185); + BOOST_CHECK_EQUAL (f->ratio_as_integer(0), 185); f = Format::from_nickname ("Scope"); BOOST_CHECK (f); - BOOST_CHECK_EQUAL (f->ratio_as_integer(), 239); + BOOST_CHECK_EQUAL (f->ratio_as_integer(0), 239); } BOOST_AUTO_TEST_CASE (util_test) @@ -328,7 +328,7 @@ BOOST_AUTO_TEST_CASE (make_dcp_test) film.set_name ("test_film"); film.set_content ("../../../test/test.mp4"); film.examine_content (); - film.set_format (Format::from_ratio (185)); + film.set_format (Format::from_nickname ("Flat")); film.set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); film.make_dcp (true); @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE (make_dcp_with_range_test) film.set_name ("test_film"); film.set_content ("../../../test/test.mp4"); film.examine_content (); - film.set_format (Format::from_ratio (185)); + film.set_format (Format::from_nickname ("Flat")); film.set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); film.set_dcp_frames (42); film.make_dcp (true); -- cgit v1.2.3 From d7801f3fe5a5ac46aa2c512bcd00be2bee39ed17 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 8 Oct 2012 00:20:10 +0100 Subject: Present fixed formats with video content and variable formats with stills. --- src/lib/format.cc | 41 +---------------------------------------- src/lib/format.h | 2 -- src/wx/film_editor.cc | 49 ++++++++++++++++++++++++++++++++++++++++++------- src/wx/film_editor.h | 5 ++++- 4 files changed, 47 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/lib/format.cc b/src/lib/format.cc index 115e03691..aaf5211f9 100644 --- a/src/lib/format.cc +++ b/src/lib/format.cc @@ -123,34 +123,6 @@ Format::from_metadata (string m) return from_id (m); } -/** @param f A Format. - * @return Index of f within our static list, or -1. - */ -int -Format::as_index (Format const * f) -{ - vector::size_type i = 0; - while (i < _formats.size() && _formats[i] != f) { - ++i; - } - - if (i == _formats.size ()) { - return -1; - } - - return i; -} - -/** @param i An index returned from as_index(). - * @return Corresponding Format. - */ -Format const * -Format::from_index (int i) -{ - assert (i >= 0 && i < int(_formats.size ())); - return _formats[i]; -} - /** @return All available formats */ vector Format::all () @@ -205,16 +177,5 @@ VariableFormat::ratio_as_float (Film const * f) const string VariableFormat::name () const { - stringstream s; - if (!_nickname.empty ()) { - s << _nickname << " ("; - } - - s << "without stretching"; - - if (!_nickname.empty ()) { - s << ")"; - } - - return s.str (); + return _nickname; } diff --git a/src/lib/format.h b/src/lib/format.h index 6172dc57d..fd6cdbece 100644 --- a/src/lib/format.h +++ b/src/lib/format.h @@ -71,9 +71,7 @@ public: static Format const * from_nickname (std::string n); static Format const * from_metadata (std::string m); - static Format const * from_index (int i); static Format const * from_id (std::string i); - static int as_index (Format const * f); static std::vector all (); static void setup_formats (); diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 9171daa5c..3b26a5537 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -182,11 +182,6 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent) _audio_delay->SetRange (-1000, 1000); _still_duration->SetRange (0, 60 * 60); - vector fmt = Format::all (); - for (vector::iterator i = fmt.begin(); i != fmt.end(); ++i) { - _format->Append (std_to_wx ((*i)->name ())); - } - vector const ct = DCPContentType::all (); for (vector::const_iterator i = ct.begin(); i != ct.end(); ++i) { _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ())); @@ -221,6 +216,7 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent) _change_dcp_range_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::change_dcp_range_clicked), 0, this); setup_visibility (); + setup_formats (); } /** Called when the left crop widget has been changed */ @@ -295,6 +291,7 @@ FilmEditor::content_changed (wxCommandEvent &) _ignore_changes = Film::NONE; setup_visibility (); + setup_formats (); } /** Called when the DCP A/B switch has been toggled */ @@ -342,10 +339,19 @@ FilmEditor::film_changed (Film::Property p) case Film::CONTENT: _content->SetPath (std_to_wx (_film->content ())); setup_visibility (); + setup_formats (); break; case Film::FORMAT: - _format->SetSelection (Format::as_index (_film->format ())); + { + int n = 0; + vector::iterator i = _formats.begin (); + while (i != _formats.end() && *i != _film->format ()) { + ++i; + ++n; + } + _format->SetSelection (n); break; + } case Film::CROP: _left_crop->SetValue (_film->crop().left); _right_crop->SetValue (_film->crop().right); @@ -445,7 +451,8 @@ FilmEditor::format_changed (wxCommandEvent &) _ignore_changes = Film::FORMAT; int const n = _format->GetSelection (); if (n >= 0) { - _film->set_format (Format::from_index (n)); + assert (n < int (_formats.size())); + _film->set_format (_formats[n]); } _ignore_changes = Film::NONE; } @@ -667,3 +674,31 @@ FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &) d->Destroy (); } + +void +FilmEditor::setup_formats () +{ + ContentType c = VIDEO; + + if (_film) { + c = _film->content_type (); + } + + _formats.clear (); + + vector fmt = Format::all (); + for (vector::iterator i = fmt.begin(); i != fmt.end(); ++i) { + if (c == VIDEO && dynamic_cast (*i)) { + _formats.push_back (*i); + } else if (c == STILL && dynamic_cast (*i)) { + _formats.push_back (*i); + } + } + + _format->Clear (); + for (vector::iterator i = _formats.begin(); i != _formats.end(); ++i) { + _format->Append (std_to_wx ((*i)->name ())); + } + + _sizer->Layout (); +} diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index ac9a5fb31..c599cd285 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -68,7 +68,8 @@ private: void change_dcp_range_clicked (wxCommandEvent &); void set_things_sensitive (bool); - + void setup_formats (); + wxControl* video_control (wxControl *); wxControl* still_control (wxControl *); @@ -125,5 +126,7 @@ private: std::list _video_controls; std::list _still_controls; + std::vector _formats; + wxSizer* _sizer; }; -- cgit v1.2.3 From e73d64612c12f2027a91fa2061992aeec3c4bb60 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 02:14:04 +0100 Subject: Remove some unnecessary code. --- src/lib/ab_transcoder.cc | 2 +- src/lib/decoder.cc | 17 +++-------------- src/lib/decoder.h | 2 -- src/lib/film.cc | 3 --- src/lib/options.h | 2 -- 5 files changed, 4 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/lib/ab_transcoder.cc b/src/lib/ab_transcoder.cc index 95492a9d8..1c20ae477 100644 --- a/src/lib/ab_transcoder.cc +++ b/src/lib/ab_transcoder.cc @@ -112,7 +112,7 @@ ABTranscoder::go () bool const b = _db->pass (); if (_job) { - _job->set_progress (float (_last_frame) / _da->decoding_frames ()); + _job->set_progress (float (_last_frame) / _fs_a->dcp_length()); } if (a && b) { diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 8aa5f77c6..324d1a296 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -112,7 +112,7 @@ Decoder::process_end () */ int64_t const audio_short_by_frames = - ((int64_t) decoding_frames() * _fs->target_sample_rate() / _fs->frames_per_second) + ((int64_t) _fs->dcp_length() * _fs->target_sample_rate() / _fs->frames_per_second) - _audio_frames_processed; if (audio_short_by_frames >= 0) { @@ -147,24 +147,13 @@ Decoder::go () while (pass () == false) { if (_job && !_ignore_length) { - _job->set_progress (float (_video_frame) / decoding_frames ()); + _job->set_progress (float (_video_frame) / _fs->dcp_length()); } } process_end (); } -/** @return Number of frames that we will be decoding */ -int -Decoder::decoding_frames () const -{ - if (_opt->num_frames > 0) { - return _opt->num_frames; - } - - return _fs->length; -} - /** Run one pass. This may or may not generate any actual video / audio data; * some decoders may require several passes to generate a single frame. * @return true if we have finished processing all data; otherwise false. @@ -177,7 +166,7 @@ Decoder::pass () _have_setup_video_filters = true; } - if (_opt->num_frames != 0 && _video_frame >= _opt->num_frames) { + if (_video_frame >= _fs->dcp_length()) { return true; } diff --git a/src/lib/decoder.h b/src/lib/decoder.h index 19ef25ede..04ff512eb 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -77,8 +77,6 @@ public: return _video_frame; } - int decoding_frames () const; - /** Emitted when a video frame is ready. * First parameter is the frame. * Second parameter is its index within the content. diff --git a/src/lib/film.cc b/src/lib/film.cc index 330ae9e5d..e2b3d4bc3 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -517,18 +517,15 @@ Film::make_dcp (bool transcode, int freq) o->out_size = format()->dcp_size (); if (dcp_frames() == 0) { /* Decode the whole film, no blacking */ - o->num_frames = 0; o->black_after = 0; } else { switch (dcp_trim_action()) { case CUT: /* Decode only part of the film, no blacking */ - o->num_frames = dcp_frames (); o->black_after = 0; break; case BLACK_OUT: /* Decode the whole film, but black some frames out */ - o->num_frames = 0; o->black_after = dcp_frames (); } } diff --git a/src/lib/options.h b/src/lib/options.h index b283e330d..1156ece1d 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -39,7 +39,6 @@ public: Options (std::string f, std::string e, std::string m) : padding (0) , apply_crop (true) - , num_frames (0) , decode_video (true) , decode_video_frequency (0) , decode_audio (true) @@ -93,7 +92,6 @@ public: float ratio; ///< ratio of the wanted output image (not considering padding) int padding; ///< number of pixels of padding (in terms of the output size) each side of the image bool apply_crop; ///< true to apply cropping - int num_frames; ///< number of video frames to run for, or 0 for all int black_after; ///< first frame for which to output a black frame, rather than the actual video content, or 0 for none bool decode_video; ///< true to decode video, otherwise false int decode_video_frequency; ///< skip frames so that this many are decoded in all (or 0) (for generating thumbnails) -- cgit v1.2.3 From f29219ed06d27dcae5e18b8b9c52dcf24554f188 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 16:02:07 +0100 Subject: Remove unused variable. --- src/lib/ffmpeg_decoder.cc | 8 +++----- src/lib/options.h | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 1096bb253..3991323ce 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -172,10 +172,8 @@ FFmpegDecoder::do_pass () int frame_finished; - if (_opt->decode_video) { - while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { - process_video (_frame); - } + while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { + process_video (_frame); } if (_audio_stream >= 0 && _opt->decode_audio) { @@ -192,7 +190,7 @@ FFmpegDecoder::do_pass () return true; } - if (_packet.stream_index == _video_stream && _opt->decode_video) { + if (_packet.stream_index == _video_stream) { int frame_finished; if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { diff --git a/src/lib/options.h b/src/lib/options.h index 1156ece1d..45a1768c2 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -39,7 +39,6 @@ public: Options (std::string f, std::string e, std::string m) : padding (0) , apply_crop (true) - , decode_video (true) , decode_video_frequency (0) , decode_audio (true) , _frame_out_path (f) @@ -93,7 +92,6 @@ public: int padding; ///< number of pixels of padding (in terms of the output size) each side of the image bool apply_crop; ///< true to apply cropping int black_after; ///< first frame for which to output a black frame, rather than the actual video content, or 0 for none - bool decode_video; ///< true to decode video, otherwise false int decode_video_frequency; ///< skip frames so that this many are decoded in all (or 0) (for generating thumbnails) bool decode_audio; ///< true to decode audio, otherwise false -- cgit v1.2.3 From 942e32c0b7aa268ec7e5bda8a74453340dad3592 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 16:04:34 +0100 Subject: Fix uninitialised variable. --- src/lib/options.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/lib/options.h b/src/lib/options.h index 45a1768c2..39068c24f 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -39,6 +39,7 @@ public: Options (std::string f, std::string e, std::string m) : padding (0) , apply_crop (true) + , black_after (0) , decode_video_frequency (0) , decode_audio (true) , _frame_out_path (f) -- cgit v1.2.3 From dc1b54d559dac0b722e8854d1f48c77a07507497 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 17:13:09 +0100 Subject: Use r_frame_rate from AVStream if avg_frame_rate is not a number; fixes problems with some WMV files. --- src/lib/ffmpeg_decoder.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 3991323ce..767299ea6 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -225,7 +225,13 @@ FFmpegDecoder::length_in_frames () const float FFmpegDecoder::frames_per_second () const { - return av_q2d (_format_context->streams[_video_stream]->avg_frame_rate); + AVStream* s = _format_context->streams[_video_stream]; + + if (s->avg_frame_rate.num && s->avg_frame_rate.den) { + return av_q2d (s->avg_frame_rate); + } + + return av_q2d (s->r_frame_rate); } int -- cgit v1.2.3 From 64f24832974e5b05dabf7117d5b2d34ea079c033 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 17:13:28 +0100 Subject: Simplify and test audio sample rate alteration. --- src/lib/film_state.cc | 16 ++++++---------- test/test.cc | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc index 3cd7091ca..3d58a4fec 100644 --- a/src/lib/film_state.cc +++ b/src/lib/film_state.cc @@ -283,18 +283,14 @@ FilmState::bytes_per_sample () const int FilmState::target_sample_rate () const { + /* Resample to a DCI-approved sample rate */ double t = dcp_audio_sample_rate (audio_sample_rate); + + /* Compensate for the fact that video will be rounded to the + nearest integer number of frames per second. + */ if (rint (frames_per_second) != frames_per_second) { - if (fabs (frames_per_second - 23.976) < 1e-6 || (fabs (frames_per_second - 29.97) < 1e-6)) { - /* 24fps or 30fps drop-frame ie {24,30} * 1000 / 1001 frames per second; - hence we need to resample the audio to dcp_audio_sample_rate * 1000 / 1001 - so that when we play it back at dcp_audio_sample_rate it is sped up - by the same amount that the video is - */ - t *= double(1000) / 1001; - } else { - throw EncodeError ("unknown fractional frame rate"); - } + t *= frames_per_second / rint (frames_per_second); } return rint (t); diff --git a/test/test.cc b/test/test.cc index ebee50ac0..d978d36a0 100644 --- a/test/test.cc +++ b/test/test.cc @@ -362,3 +362,26 @@ BOOST_AUTO_TEST_CASE (make_dcp_with_range_test) BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false); } + +BOOST_AUTO_TEST_CASE (audio_sampling_rate_test) +{ + FilmState fs; + fs.frames_per_second = 24; + + fs.audio_sample_rate = 48000; + BOOST_CHECK_EQUAL (fs.target_sample_rate(), 48000); + + fs.audio_sample_rate = 44100; + BOOST_CHECK_EQUAL (fs.target_sample_rate(), 48000); + + fs.audio_sample_rate = 80000; + BOOST_CHECK_EQUAL (fs.target_sample_rate(), 96000); + + fs.frames_per_second = 23.976; + fs.audio_sample_rate = 48000; + BOOST_CHECK_EQUAL (fs.target_sample_rate(), 47952); + + fs.frames_per_second = 29.97; + fs.audio_sample_rate = 48000; + BOOST_CHECK_EQUAL (fs.target_sample_rate(), 47952); +} -- cgit v1.2.3 From b03b2c447a8ed9f855d09a62609ca03cc705fdbf Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 21:58:05 +0100 Subject: Fix some POSIX-isms. --- src/lib/j2k_wav_encoder.cc | 12 ++++++------ test/test.cc | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/lib/j2k_wav_encoder.cc b/src/lib/j2k_wav_encoder.cc index 2f892948d..a1f70a08a 100644 --- a/src/lib/j2k_wav_encoder.cc +++ b/src/lib/j2k_wav_encoder.cc @@ -149,7 +149,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) while (1) { - TIMING ("encoder thread %1 sleeps", pthread_self ()); + TIMING ("encoder thread %1 sleeps", boost::this_thread::get_id()); boost::mutex::scoped_lock lock (_worker_mutex); while (_queue.empty () && !_process_end) { _worker_condition.wait (lock); @@ -159,9 +159,9 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) return; } - TIMING ("encoder thread %1 wakes with queue of %2", pthread_self(), _queue.size()); + TIMING ("encoder thread %1 wakes with queue of %2", boost::this_thread::get_id(), _queue.size()); boost::shared_ptr vf = _queue.front (); - _log->log (String::compose ("Encoder thread %1 pops frame %2 from queue", pthread_self(), vf->frame())); + _log->log (String::compose ("Encoder thread %1 pops frame %2 from queue", boost::this_thread::get_id(), vf->frame())); _queue.pop_front (); lock.unlock (); @@ -193,9 +193,9 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) } else { try { - TIMING ("encoder thread %1 begins local encode of %2", pthread_self(), vf->frame()); + TIMING ("encoder thread %1 begins local encode of %2", boost::this_thread::get_id(), vf->frame()); encoded = vf->encode_locally (); - TIMING ("encoder thread %1 finishes local encode of %2", pthread_self(), vf->frame()); + TIMING ("encoder thread %1 finishes local encode of %2", boost::this_thread::get_id(), vf->frame()); } catch (std::exception& e) { _log->log (String::compose ("Local encode failed (%1)", e.what ())); } @@ -206,7 +206,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server) frame_done (vf->frame ()); } else { lock.lock (); - _log->log (String::compose ("Encoder thread %1 pushes frame %2 back onto queue after failure", pthread_self(), vf->frame())); + _log->log (String::compose ("Encoder thread %1 pushes frame %2 back onto queue after failure", boost::this_thread::get_id(), vf->frame())); _queue.push_front (vf); lock.unlock (); } diff --git a/test/test.cc b/test/test.cc index d978d36a0..26bca33e5 100644 --- a/test/test.cc +++ b/test/test.cc @@ -34,6 +34,7 @@ #include "dcp_video_frame.h" #include "config.h" #include "server.h" +#include "cross.h" #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE dvdomatic_test #include @@ -333,7 +334,7 @@ BOOST_AUTO_TEST_CASE (make_dcp_test) film.make_dcp (true); while (JobManager::instance()->work_to_do ()) { - sleep (1); + dvdomatic_sleep (1); } BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false); @@ -357,7 +358,7 @@ BOOST_AUTO_TEST_CASE (make_dcp_with_range_test) film.make_dcp (true); while (JobManager::instance()->work_to_do ()) { - sleep (1); + dvdomatic_sleep (1); } BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false); -- cgit v1.2.3