+2015-09-30 Carl Hetherington <cth@carlh.net>
+
+ * Fix various confusions with subtitles and
+ changing video frame rates.
+
2015-09-29 Carl Hetherington <cth@carlh.net>
* Version 2.3.10 released.
return false;
}
+ double subtitle_video_frame_rate () const {
+ return video_frame_rate ();
+ }
+
boost::filesystem::path directory () const;
bool encrypted () const {
#include "font.h"
#include "dcp_subtitle_content.h"
#include "raw_convert.h"
+#include "film.h"
#include <dcp/interop_subtitle_asset.h>
#include <dcp/smpte_subtitle_asset.h>
#include <dcp/interop_load_font_node.h>
DCPSubtitleContent::DCPSubtitleContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
: Content (film, node)
, SubtitleContent (film, node, version)
- , _length (node->number_child<DCPTime::Type> ("Length"))
+ , _length (node->number_child<ContentTime::Type> ("Length"))
+ , _frame_rate (node->optional_number_child<int>("SubtitleFrameRate"))
{
}
shared_ptr<dcp::SMPTESubtitleAsset> smpte = dynamic_pointer_cast<dcp::SMPTESubtitleAsset> (sc);
if (smpte) {
_subtitle_language = smpte->language().get_value_or ("");
+ _frame_rate = smpte->edit_rate().numerator;
}
- _length = DCPTime::from_seconds (sc->latest_subtitle_out().as_seconds ());
+ _length = ContentTime::from_seconds (sc->latest_subtitle_out().as_seconds ());
BOOST_FOREACH (shared_ptr<dcp::LoadFontNode> i, sc->load_font_nodes ()) {
add_font (shared_ptr<Font> (new Font (i->id)));
DCPTime
DCPSubtitleContent::full_length () const
{
- /* XXX: this assumes that the timing of the subtitle file is appropriate
- for the DCP's frame rate.
- */
- return _length;
+ shared_ptr<const Film> film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+ FrameRateChange const frc (subtitle_video_frame_rate(), film->video_frame_rate());
+ return DCPTime (_length, frc);
}
string
SubtitleContent::as_xml (node);
node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ()));
}
+
+void
+DCPSubtitleContent::set_subtitle_video_frame_rate (int r)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _frame_rate = r;
+ }
+
+ signal_changed (SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE);
+}
+
+double
+DCPSubtitleContent::subtitle_video_frame_rate () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ if (_frame_rate) {
+ return _frame_rate.get ();
+ }
+
+ /* No frame rate specified, so assume this content has been
+ prepared for any concurrent video content.
+ */
+ shared_ptr<const Film> film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+ return film->active_frame_rate_change(position()).source;
+}
return false;
}
+ double subtitle_video_frame_rate () const;
+ void set_subtitle_video_frame_rate (int r);
+
private:
- DCPTime _length;
+ ContentTime _length;
+ /** Video frame rate that this content has been prepared for, if known */
+ boost::optional<double> _frame_rate;
};
/* SubtitleContent */
bool has_text_subtitles () const;
bool has_image_subtitles () const;
+ double subtitle_video_frame_rate () const {
+ return video_frame_rate ();
+ }
void set_filters (std::vector<Filter const *> const &);
SubRipContent::SubRipContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
: Content (film, node)
, SubtitleContent (film, node, version)
- , _length (node->number_child<DCPTime::Type> ("Length"))
+ , _length (node->number_child<ContentTime::Type> ("Length"))
+ , _frame_rate (node->optional_number_child<double>("SubtitleFrameRate"))
{
}
Content::examine (job);
SubRip s (shared_from_this ());
- shared_ptr<const Film> film = _film.lock ();
- DCPOMATIC_ASSERT (film);
-
- DCPTime len (s.length (), film->active_frame_rate_change (position ()));
-
/* Default to turning these subtitles on */
set_use_subtitles (true);
boost::mutex::scoped_lock lm (_mutex);
- _length = len;
+ _length = s.length ();
add_font (shared_ptr<Font> (new Font (font_id)));
}
DCPTime
SubRipContent::full_length () const
{
- /* XXX: this assumes that the timing of the SubRip file is appropriate
- for the DCP's frame rate.
+ shared_ptr<const Film> film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+ FrameRateChange const frc (subtitle_video_frame_rate(), film->video_frame_rate ());
+ return DCPTime (_length, frc);
+}
+
+void
+SubRipContent::set_subtitle_video_frame_rate (int r)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _frame_rate = r;
+ }
+
+ signal_changed (SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE);
+}
+
+double
+SubRipContent::subtitle_video_frame_rate () const
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ if (_frame_rate) {
+ return _frame_rate.get ();
+ }
+ }
+
+ /* No frame rate specified, so assume this content has been
+ prepared for any concurrent video content.
*/
- return _length;
+ shared_ptr<const Film> film = _film.lock ();
+ DCPOMATIC_ASSERT (film);
+ return film->active_frame_rate_change(position()).source;
}
return false;
}
+ double subtitle_video_frame_rate () const;
+ void set_subtitle_video_frame_rate (int r);
+
static std::string const font_id;
private:
- DCPTime _length;
+ ContentTime _length;
+ /** Video frame rate that this content has been prepared for, if known */
+ boost::optional<double> _frame_rate;
};
int const SubtitleContentProperty::BURN_SUBTITLES = 505;
int const SubtitleContentProperty::SUBTITLE_LANGUAGE = 506;
int const SubtitleContentProperty::FONTS = 507;
+int const SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE = 508;
SubtitleContent::SubtitleContent (shared_ptr<const Film> film)
: Content (film)
static int const BURN_SUBTITLES;
static int const SUBTITLE_LANGUAGE;
static int const FONTS;
+ static int const SUBTITLE_VIDEO_FRAME_RATE;
};
/** @class SubtitleContent
bool has_subtitles () const;
virtual bool has_text_subtitles () const = 0;
virtual bool has_image_subtitles () const = 0;
+ virtual double subtitle_video_frame_rate () const = 0;
void add_font (boost::shared_ptr<Font> font);
*/
-#include "lib/content.h"
-#include "lib/image_content.h"
-#include "lib/raw_convert.h"
#include "timing_panel.h"
#include "wx_util.h"
#include "film_viewer.h"
#include "timecode.h"
#include "content_panel.h"
+#include "lib/content.h"
+#include "lib/image_content.h"
+#include "lib/raw_convert.h"
+#include "lib/subtitle_content.h"
+#include "lib/dcp_subtitle_content.h"
+#include "lib/subrip_content.h"
#include <boost/foreach.hpp>
#include <set>
#include <iostream>
} else if (
property == ContentProperty::LENGTH ||
property == VideoContentProperty::VIDEO_FRAME_RATE ||
- property == VideoContentProperty::VIDEO_FRAME_TYPE
+ property == VideoContentProperty::VIDEO_FRAME_TYPE ||
+ property == SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE
) {
update_full_length ();
property == ContentProperty::TRIM_START ||
property == ContentProperty::TRIM_END ||
property == VideoContentProperty::VIDEO_FRAME_RATE ||
- property == VideoContentProperty::VIDEO_FRAME_TYPE
+ property == VideoContentProperty::VIDEO_FRAME_TYPE ||
+ property == SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE
) {
update_play_length ();
}
}
+ if (property == SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE) {
+ shared_ptr<const SubtitleContent> check;
+ int count = 0;
+ BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
+ shared_ptr<const SubtitleContent> t = dynamic_pointer_cast<const SubtitleContent> (i);
+ if (t) {
+ check = t;
+ ++count;
+ }
+ }
+ if (count == 1) {
+ checked_set (_video_frame_rate, raw_convert<string> (check->subtitle_video_frame_rate (), 5));
+ _video_frame_rate->Enable (true);
+ } else {
+ checked_set (_video_frame_rate, wxT (""));
+ _video_frame_rate->Enable (false);
+ }
+ }
+
bool have_still = false;
BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (i);
{
BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (i);
+ shared_ptr<DCPSubtitleContent> dsc = dynamic_pointer_cast<DCPSubtitleContent> (i);
+ shared_ptr<SubRipContent> ssc = dynamic_pointer_cast<SubRipContent> (i);
if (vc) {
vc->set_video_frame_rate (raw_convert<double> (wx_to_std (_video_frame_rate->GetValue ())));
+ } else if (dsc) {
+ dsc->set_subtitle_video_frame_rate (raw_convert<double> (wx_to_std (_video_frame_rate->GetValue ())));
+ } else if (ssc) {
+ ssc->set_subtitle_video_frame_rate (raw_convert<double> (wx_to_std (_video_frame_rate->GetValue ())));
}
_set_video_frame_rate->Enable (false);
}
film_content_changed (ContentProperty::TRIM_START);
film_content_changed (ContentProperty::TRIM_END);
film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
+ film_content_changed (SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE);
}
void