+++ /dev/null
-/*
- Copyright (C) 2014 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.
-
-*/
-
-#include "content_subtitle.h"
-
-ContentTimePeriod
-ContentTextSubtitle::period () const
-{
- /* XXX: assuming we have some subs and they are all at the same time */
- DCPOMATIC_ASSERT (!subs.empty ());
- return ContentTimePeriod (
- ContentTime::from_seconds (subs.front().in().as_seconds()),
- ContentTime::from_seconds (subs.front().out().as_seconds())
- );
-}
class ContentSubtitle
{
public:
- virtual ContentTimePeriod period () const = 0;
+ ContentSubtitle (ContentTimePeriod p)
+ : _period (p)
+ {}
+
+ ContentTimePeriod period () const {
+ return _period;
+ }
+
+private:
+ ContentTimePeriod _period;
};
class ContentImageSubtitle : public ContentSubtitle
{
public:
ContentImageSubtitle (ContentTimePeriod p, boost::shared_ptr<Image> im, dcpomatic::Rect<double> r)
- : sub (im, r)
- , _period (p)
+ : ContentSubtitle (p)
+ , sub (im, r)
{}
- ContentTimePeriod period () const {
- return _period;
- }
-
/* Our subtitle, with its rectangle unmodified by any offsets or scales that the content specifies */
ImageSubtitle sub;
-
-private:
- ContentTimePeriod _period;
};
+/** A text subtitle. We store the time period separately (as well as in the dcp::SubtitleStrings)
+ * as the dcp::SubtitleString timings are sometimes quite heavily quantised and this causes problems
+ * when we want to compare the quantised periods to the unquantised ones.
+ */
class ContentTextSubtitle : public ContentSubtitle
{
public:
- ContentTextSubtitle (std::list<dcp::SubtitleString> s)
- : subs (s)
+ ContentTextSubtitle (ContentTimePeriod p, std::list<dcp::SubtitleString> s)
+ : ContentSubtitle (p)
+ , subs (s)
{}
- ContentTimePeriod period () const;
-
std::list<dcp::SubtitleString> subs;
};
list<dcp::SubtitleString> s;
s.push_back (*_next);
- text_subtitle (s);
+ text_subtitle (content_time_period (*_next), s);
++_next;
return false;
list<ContentTimePeriod> d;
for (list<dcp::SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
- ContentTimePeriod period (
- ContentTime::from_seconds (i->in().as_seconds ()),
- ContentTime::from_seconds (i->out().as_seconds ())
- );
-
+ ContentTimePeriod period = content_time_period (*i);
if ((starting && p.contains (period.from)) || (!starting && p.overlaps (period))) {
d.push_back (period);
}
return d;
}
+ContentTimePeriod
+DCPSubtitleDecoder::content_time_period (dcp::SubtitleString s) const
+{
+ return ContentTimePeriod (
+ ContentTime::from_seconds (s.in().as_seconds ()),
+ ContentTime::from_seconds (s.out().as_seconds ())
+ );
+}
private:
std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod, bool starting) const;
std::list<ContentTimePeriod> text_subtitles_during (ContentTimePeriod, bool starting) const;
+ ContentTimePeriod content_time_period (dcp::SubtitleString s) const;
std::list<dcp::SubtitleString> _subtitles;
std::list<dcp::SubtitleString>::const_iterator _next;
}
}
- text_subtitle (out);
+ text_subtitle (content_time_period (_subtitles[_next]), out);
+
++_next;
return false;
}
list<ContentTimePeriod> d;
for (vector<sub::Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
-
- ContentTimePeriod t (
- ContentTime::from_seconds (i->from.all_as_seconds()),
- ContentTime::from_seconds (i->to.all_as_seconds())
- );
-
+ ContentTimePeriod t = content_time_period (*i);
if ((starting && p.contains (t.from)) || (!starting && p.overlaps (t))) {
d.push_back (t);
}
return d;
}
+
+ContentTimePeriod
+SubRipDecoder::content_time_period (sub::Subtitle s) const
+{
+ return ContentTimePeriod (
+ ContentTime::from_seconds (s.from.all_as_seconds()),
+ ContentTime::from_seconds (s.to.all_as_seconds())
+ );
+}
private:
std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod, bool starting) const;
std::list<ContentTimePeriod> text_subtitles_during (ContentTimePeriod, bool starting) const;
+ ContentTimePeriod content_time_period (sub::Subtitle s) const;
size_t _next;
};
*/
-#include <boost/shared_ptr.hpp>
#include "subtitle_decoder.h"
#include "subtitle_content.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/foreach.hpp>
using std::list;
using std::cout;
}
void
-SubtitleDecoder::text_subtitle (list<dcp::SubtitleString> s)
+SubtitleDecoder::text_subtitle (ContentTimePeriod period, list<dcp::SubtitleString> s)
{
- _decoded_text_subtitles.push_back (ContentTextSubtitle (s));
+ _decoded_text_subtitles.push_back (ContentTextSubtitle (period, s));
}
/** @param sp Full periods of subtitles that are showing or starting during the specified period */
void seek (ContentTime, bool);
void image_subtitle (ContentTimePeriod period, boost::shared_ptr<Image>, dcpomatic::Rect<double>);
- void text_subtitle (std::list<dcp::SubtitleString>);
+ void text_subtitle (ContentTimePeriod period, std::list<dcp::SubtitleString>);
std::list<ContentImageSubtitle> _decoded_image_subtitles;
std::list<ContentTextSubtitle> _decoded_text_subtitles;
config.cc
content.cc
content_factory.cc
- content_subtitle.cc
cross.cc
data.cc
dcp_content.cc
obj.name = 'libdcpomatic2'
obj.export_includes = ['..']
obj.uselib = """
- AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE
+ AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE
BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2
SNDFILE OPENJPEG POSTPROC TIFF MAGICK SSH DCP CXML GLIB LZMA XML++
CURL ZIP PANGOMM CAIROMM XMLSEC SUB
tested_by.Add (wxT ("Mauro Ottonello"));
tested_by.Add (wxT ("Peter Puchner"));
tested_by.Add (wxT ("Markus Raab"));
+ tested_by.Add (wxT ("Michael Reckert"));
tested_by.Add (wxT ("Greg Rooke"));
tested_by.Add (wxT ("Elad Saad"));
tested_by.Add (wxT ("Karim Senoucci"));
#include "lib/font.h"
#include "test.h"
#include <boost/test/unit_test.hpp>
+#include <boost/algorithm/string.hpp>
+#include <list>
+using std::string;
+using std::list;
using boost::shared_ptr;
/** Make a very short DCP with a single subtitle from .srt with no specified fonts */
check_dcp ("test/data/srt_subtitle_test2", film->dir (film->dcp_name ()));
}
+/** Make another DCP with a longer .srt file */
+BOOST_AUTO_TEST_CASE (srt_subtitle_test3)
+{
+ shared_ptr<Film> film = new_test_film ("srt_subtitle_test3");
+
+ film->set_container (Ratio::from_id ("185"));
+ film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
+ film->set_name ("frobozz");
+ film->set_interop (true);
+ shared_ptr<SubRipContent> content (new SubRipContent (film, private_data / "Ankoemmling.srt"));
+ film->examine_and_add_content (content);
+ wait_for_jobs ();
+
+ content->set_use_subtitles (true);
+ content->set_burn_subtitles (false);
+
+ film->make_dcp ();
+ wait_for_jobs ();
+
+ /* Find the subtitle file and check it */
+ for (
+ boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->directory() / film->dcp_name (false));
+ i != boost::filesystem::directory_iterator ();
+ ++i) {
+
+ if (boost::filesystem::is_directory (i->path ())) {
+ for (
+ boost::filesystem::directory_iterator j = boost::filesystem::directory_iterator (i->path ());
+ j != boost::filesystem::directory_iterator ();
+ ++j) {
+
+ std::cout << j->path().string() << "\n";
+
+ if (boost::algorithm::starts_with (j->path().leaf().string(), "sub_")) {
+ list<string> ignore;
+ ignore.push_back ("SubtitleID");
+ check_xml (*j, private_data / "Ankoemmling.xml", ignore);
+ }
+ }
+ }
+ }
+}