From 04ef57589ebb7c0de3377172a03b24698fd2364a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 18 Mar 2014 14:24:08 +0000 Subject: [PATCH] Tentative support for 3D from alternate frames. Also remove references to libpostproc. Requested-by: Jean-Jacques Mantello --- ChangeLog | 4 ++++ src/lib/ffmpeg.cc | 1 - src/lib/ffmpeg_content.cc | 6 +++--- src/lib/ffmpeg_decoder.cc | 2 +- src/lib/ffmpeg_decoder.h | 1 - src/lib/image.cc | 1 - src/lib/image_content.cc | 2 +- src/lib/scaler.h | 2 +- src/lib/types.h | 3 ++- src/lib/util.cc | 2 -- src/lib/video_content.cc | 6 +++++- src/lib/video_content.h | 9 +++++++++ src/lib/video_decoder.cc | 3 +++ src/lib/video_decoder.h | 3 +++ src/wx/timing_panel.cc | 6 +++++- src/wx/video_panel.cc | 1 + test/play_test.cc | 4 ++-- 17 files changed, 40 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a99d30ff..45847805a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-03-18 Carl Hetherington + + * Tentative support for 3D from alternate frames of the source. + 2014-03-17 Carl Hetherington * Improve behaviour of the position slider at the end of films. diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index fae9baa2b..60eea6ec7 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -21,7 +21,6 @@ extern "C" { #include #include #include -#include } #include "ffmpeg.h" #include "ffmpeg_content.h" diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index fadeec9cd..b7551c96a 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -239,7 +239,7 @@ FFmpegContent::information () const stringstream s; - s << String::compose (_("%1 frames; %2 frames per second"), video_length(), video_frame_rate()) << "\n"; + s << String::compose (_("%1 frames; %2 frames per second"), video_length_after_3d_combine(), video_frame_rate()) << "\n"; s << VideoContent::information (); return s.str (); @@ -272,7 +272,7 @@ FFmpegContent::audio_length () const { int const cafr = content_audio_frame_rate (); int const vfr = video_frame_rate (); - VideoContent::Frame const vl = video_length (); + VideoContent::Frame const vl = video_length_after_3d_combine (); boost::mutex::scoped_lock lm (_mutex); if (!_audio_stream) { @@ -429,7 +429,7 @@ FFmpegContent::full_length () const assert (film); FrameRateConversion frc (video_frame_rate (), film->video_frame_rate ()); - return video_length() * frc.factor() * TIME_HZ / film->video_frame_rate (); + return video_length_after_3d_combine() * frc.factor() * TIME_HZ / film->video_frame_rate (); } AudioMapping diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 851c64606..1920f9275 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -142,7 +142,7 @@ FFmpegDecoder::flush () } /* Stop us being asked for any more data */ - _video_position = _ffmpeg_content->video_length (); + _video_position = _ffmpeg_content->video_length_after_3d_combine (); _audio_position = _ffmpeg_content->audio_length (); } diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 63a8f0c71..d4b4fa1c0 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -29,7 +29,6 @@ #include extern "C" { #include -#include } #include "util.h" #include "decoder.h" diff --git a/src/lib/image.cc b/src/lib/image.cc index 25d1ef276..d083cf3f6 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -26,7 +26,6 @@ extern "C" { #include #include #include -#include } #include "image.h" #include "exceptions.h" diff --git a/src/lib/image_content.cc b/src/lib/image_content.cc index fd0b57894..13f7c52e3 100644 --- a/src/lib/image_content.cc +++ b/src/lib/image_content.cc @@ -127,7 +127,7 @@ ImageContent::full_length () const assert (film); FrameRateConversion frc (video_frame_rate(), film->video_frame_rate ()); - return video_length() * frc.factor() * TIME_HZ / video_frame_rate(); + return video_length_after_3d_combine() * frc.factor() * TIME_HZ / video_frame_rate(); } string diff --git a/src/lib/scaler.h b/src/lib/scaler.h index 6a039edd8..14077ff1d 100644 --- a/src/lib/scaler.h +++ b/src/lib/scaler.h @@ -36,7 +36,7 @@ class Scaler : public boost::noncopyable public: Scaler (int f, std::string i, std::string n); - /** @return id used for calls to FFmpeg's pp_postprocess */ + /** @return id used for calls to FFmpeg's sws_getContext */ int ffmpeg_id () const { return _ffmpeg_id; } diff --git a/src/lib/types.h b/src/lib/types.h index 96b993a8e..8a16818bd 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -69,7 +69,8 @@ enum VideoFrameType { VIDEO_FRAME_TYPE_2D, VIDEO_FRAME_TYPE_3D_LEFT_RIGHT, - VIDEO_FRAME_TYPE_3D_TOP_BOTTOM + VIDEO_FRAME_TYPE_3D_TOP_BOTTOM, + VIDEO_FRAME_TYPE_3D_ALTERNATE }; enum Eyes diff --git a/src/lib/util.cc b/src/lib/util.cc index 35385ab40..85c52b039 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -57,7 +57,6 @@ extern "C" { #include #include #include -#include #include } #include "util.h" @@ -248,7 +247,6 @@ dependency_version_summary () << N_("libavfilter ") << ffmpeg_version_to_string (avfilter_version()) << N_(", ") << N_("libavformat ") << ffmpeg_version_to_string (avformat_version()) << N_(", ") << N_("libavutil ") << ffmpeg_version_to_string (avutil_version()) << N_(", ") - << N_("libpostproc ") << ffmpeg_version_to_string (postproc_version()) << N_(", ") << N_("libswscale ") << ffmpeg_version_to_string (swscale_version()) << N_(", ") << MagickVersion << N_(", ") << N_("libssh ") << ssh_version (0) << N_(", ") diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 966b8e8b3..4a1ef95ac 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -317,7 +317,10 @@ VideoContent::set_video_frame_type (VideoFrameType t) string VideoContent::technical_summary () const { - return String::compose ("video: length %1, size %2x%3, rate %4", video_length(), video_size().width, video_size().height, video_frame_rate()); + return String::compose ( + "video: length %1, size %2x%3, rate %4", + video_length_after_3d_combine(), video_size().width, video_size().height, video_frame_rate() + ); } libdcp::Size @@ -326,6 +329,7 @@ VideoContent::video_size_after_3d_split () const libdcp::Size const s = video_size (); switch (video_frame_type ()) { case VIDEO_FRAME_TYPE_2D: + case VIDEO_FRAME_TYPE_3D_ALTERNATE: return s; case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT: return libdcp::Size (s.width / 2, s.height); diff --git a/src/lib/video_content.h b/src/lib/video_content.h index ea4676cec..f846b7ac9 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -96,6 +96,15 @@ public: return _video_length; } + VideoContent::Frame video_length_after_3d_combine () const { + boost::mutex::scoped_lock lm (_mutex); + if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) { + return _video_length / 2; + } + + return _video_length; + } + libdcp::Size video_size () const { boost::mutex::scoped_lock lm (_mutex); return _video_size; diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc index e7ddec5e6..3ae963a20 100644 --- a/src/lib/video_decoder.cc +++ b/src/lib/video_decoder.cc @@ -40,6 +40,9 @@ VideoDecoder::video (shared_ptr image, bool same, VideoContent::Fra case VIDEO_FRAME_TYPE_2D: Video (image, EYES_BOTH, same, frame); break; + case VIDEO_FRAME_TYPE_3D_ALTERNATE: + Video (image, (frame % 2) ? EYES_RIGHT : EYES_LEFT, same, frame / 2); + break; case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT: { int const half = image->size().width / 2; diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h index 142320a04..255a038a9 100644 --- a/src/lib/video_decoder.h +++ b/src/lib/video_decoder.h @@ -51,6 +51,9 @@ protected: void video (boost::shared_ptr, bool, VideoContent::Frame); boost::shared_ptr _video_content; + /** This is in frames without taking 3D into account (e.g. if we are doing 3D alternate, + * this would equal 2 on the left-eye second frame (not 1)). + */ VideoContent::Frame _video_position; }; diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 34702463c..2321fd0df 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -87,7 +87,11 @@ TimingPanel::film_content_changed (int property) } else { _position->set (0, 24); } - } else if (property == ContentProperty::LENGTH || property == VideoContentProperty::VIDEO_FRAME_RATE) { + } else if ( + property == ContentProperty::LENGTH || + property == VideoContentProperty::VIDEO_FRAME_RATE || + property == VideoContentProperty::VIDEO_FRAME_TYPE + ) { if (content) { _full_length->set (content->full_length (), _editor->film()->video_frame_rate ()); _play_length->set (content->length_after_trim (), _editor->film()->video_frame_rate ()); diff --git a/src/wx/video_panel.cc b/src/wx/video_panel.cc index 38604248c..56848907b 100644 --- a/src/wx/video_panel.cc +++ b/src/wx/video_panel.cc @@ -196,6 +196,7 @@ VideoPanel::VideoPanel (FilmEditor* e) _frame_type->wrapped()->Append (_("2D")); _frame_type->wrapped()->Append (_("3D left/right")); _frame_type->wrapped()->Append (_("3D top/bottom")); + _frame_type->wrapped()->Append (_("3D alternate")); _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this)); _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this)); diff --git a/test/play_test.cc b/test/play_test.cc index dfa597431..51e227256 100644 --- a/test/play_test.cc +++ b/test/play_test.cc @@ -89,13 +89,13 @@ BOOST_AUTO_TEST_CASE (play_test) film->examine_and_add_content (A); wait_for_jobs (); - BOOST_CHECK_EQUAL (A->video_length(), 16); + BOOST_CHECK_EQUAL (A->video_length_after_3d_combine(), 16); shared_ptr B (new FFmpegContent (film, "test/data/red_30.mp4")); film->examine_and_add_content (B); wait_for_jobs (); - BOOST_CHECK_EQUAL (B->video_length(), 16); + BOOST_CHECK_EQUAL (B->video_length_after_3d_combine(), 16); /* Film should have been set to 25fps */ BOOST_CHECK_EQUAL (film->video_frame_rate(), 25); -- 2.30.2