summaryrefslogtreecommitdiff
path: root/src/lib/hints.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/hints.cc')
-rw-r--r--src/lib/hints.cc109
1 files changed, 63 insertions, 46 deletions
diff --git a/src/lib/hints.cc b/src/lib/hints.cc
index 99882ec0e..879c8a5dd 100644
--- a/src/lib/hints.cc
+++ b/src/lib/hints.cc
@@ -44,16 +44,19 @@
#include <fmt/format.h>
#include <boost/algorithm/string.hpp>
#include <iostream>
+#include <numeric>
#include "i18n.h"
using std::cout;
using std::make_shared;
+using std::map;
using std::max;
using std::shared_ptr;
using std::string;
using std::weak_ptr;
+using std::vector;
using boost::optional;
using namespace dcpomatic;
#if BOOST_VERSION >= 106100
@@ -227,7 +230,7 @@ Hints::check_speed_up()
optional<double> lowest_speed_up;
optional<double> highest_speed_up;
for (auto i: film()->content()) {
- double spu = film()->active_frame_rate_change(i->position()).speed_up;
+ double spu = film()->active_frame_rate_change(i->position()).speed_up();
if (!lowest_speed_up || spu < *lowest_speed_up) {
lowest_speed_up = spu;
}
@@ -367,14 +370,6 @@ Hints::check_loudness()
}
-static
-bool
-subtitle_mxf_too_big(shared_ptr<dcp::TextAsset> asset)
-{
- return asset && asset->file() && dcp::filesystem::file_size(*asset->file()) >= (MAX_TEXT_MXF_SIZE - SIZE_SLACK);
-}
-
-
void
Hints::check_out_of_range_markers()
{
@@ -497,10 +492,6 @@ try
hint(_("At least one of your subtitle lines has more than 79 characters. You should make each line 79 characters at most in length."));
}
- bool ccap_xml_too_big = false;
- bool ccap_mxf_too_big = false;
- bool subs_mxf_too_big = false;
-
auto dcp_dir = film->dir("hints") / dcpomatic::get_process_id();
dcp::filesystem::remove_all(dcp_dir);
@@ -509,31 +500,39 @@ try
dcp::DCP dcp(dcp_dir);
dcp.read();
DCPOMATIC_ASSERT(dcp.cpls().size() == 1);
+ optional<size_t> largest_ccap_xml;
+ optional<size_t> largest_ccap_mxf;
+ optional<size_t> largest_sub_mxf;
for (auto reel: dcp.cpls()[0]->reels()) {
for (auto ccap: reel->closed_captions()) {
- if (ccap->asset() && ccap->asset()->xml_as_string().length() > static_cast<size_t>(MAX_CLOSED_CAPTION_XML_SIZE - SIZE_SLACK) && !ccap_xml_too_big) {
- hint(_(
- "At least one of your closed caption files' XML part is larger than " MAX_CLOSED_CAPTION_XML_SIZE_TEXT
- ". You should divide the DCP into shorter reels."
- ));
- ccap_xml_too_big = true;
- }
- if (subtitle_mxf_too_big(ccap->asset()) && !ccap_mxf_too_big) {
- hint(_(
- "At least one of your closed caption files is larger than " MAX_TEXT_MXF_SIZE_TEXT
- " in total. You should divide the DCP into shorter reels."
- ));
- ccap_mxf_too_big = true;
+ largest_ccap_xml = std::max(ccap->asset()->xml_as_string().length(), largest_ccap_xml.get_value_or(0));
+ if (ccap->asset() && ccap->asset()->file()) {
+ largest_ccap_mxf = std::max(dcp::filesystem::file_size(*ccap->asset()->file()), largest_ccap_mxf.get_value_or(0));
}
}
- if (reel->main_subtitle() && subtitle_mxf_too_big(reel->main_subtitle()->asset()) && !subs_mxf_too_big) {
- hint(_(
- "At least one of your subtitle files is larger than " MAX_TEXT_MXF_SIZE_TEXT " in total. "
- "You should divide the DCP into shorter reels."
- ));
- subs_mxf_too_big = true;
+ if (reel->main_subtitle() && reel->main_subtitle()->asset() && reel->main_subtitle()->asset()->file()) {
+ largest_sub_mxf = std::max(dcp::filesystem::file_size(*reel->main_subtitle()->asset()->file()), largest_sub_mxf.get_value_or(0));
}
}
+
+ if (largest_ccap_xml && *largest_ccap_xml > static_cast<size_t>(MAX_CLOSED_CAPTION_XML_SIZE - SIZE_SLACK)) {
+ hint(fmt::format(_(
+ "At least one of your closed caption files' XML part is larger than " MAX_CLOSED_CAPTION_XML_SIZE_TEXT
+ ". The largest XML part is {}KB. You should divide the DCP into shorter reels."
+ ), *largest_ccap_xml / 1000));
+ }
+ if (largest_ccap_mxf && *largest_ccap_mxf >= (MAX_TEXT_MXF_SIZE - SIZE_SLACK)) {
+ hint(fmt::format(_(
+ "At least one of your closed caption files is larger than " MAX_TEXT_MXF_SIZE_TEXT
+ " in total. The largest file is {}MB. You should divide the DCP into shorter reels."
+ ), *largest_ccap_mxf / 1000000));
+ }
+ if (largest_sub_mxf && *largest_sub_mxf >= (MAX_TEXT_MXF_SIZE - SIZE_SLACK)) {
+ hint(fmt::format(_(
+ "At least one of your subtitle files is larger than " MAX_TEXT_MXF_SIZE_TEXT " in total. "
+ "The largest file is {}MB. You should divide the DCP into shorter reels."
+ ), *largest_sub_mxf / 1000000));
+ }
dcp::filesystem::remove_all(dcp_dir);
emit(boost::bind(boost::ref(Finished)));
@@ -584,24 +583,42 @@ Hints::text(PlayerText text, TextType type, optional<DCPTextTrack> track, DCPTim
void
Hints::closed_caption(PlayerText text, DCPTimePeriod period)
{
- int lines = text.string.size();
- for (auto i: text.string) {
- if (utf8_strlen(i.text()) > MAX_CLOSED_CAPTION_LENGTH) {
- ++lines;
- if (!_long_ccap) {
- _long_ccap = true;
- hint(
- fmt::format(
- "At least one of your closed caption lines has more than {} characters. "
- "It is advisable to make each line {} characters at most in length.",
- MAX_CLOSED_CAPTION_LENGTH,
- MAX_CLOSED_CAPTION_LENGTH)
- );
+ map<float, vector<StringText>> lines;
+ for (auto const& line: text.string) {
+ bool added = false;
+ for (auto& existing: lines) {
+ if (std::abs(existing.first - line.v_position()) < dcp::ALIGN_EPSILON) {
+ existing.second.push_back(line);
+ added = true;
}
}
+ if (!added) {
+ lines[line.v_position()] = { line };
+ }
+ }
+
+ for (auto const& line: lines) {
+ int const length = std::accumulate(
+ line.second.begin(),
+ line.second.end(),
+ 0,
+ [](int acc, StringText const& text) {
+ return acc + dcp::utf8_strlen(text.text());
+ });
+
+ if (length > MAX_CLOSED_CAPTION_LENGTH && !_long_ccap) {
+ _long_ccap = true;
+ hint(
+ fmt::format(
+ "At least one of your closed caption lines has more than {} characters. "
+ "It is advisable to make each line {} characters at most in length.",
+ MAX_CLOSED_CAPTION_LENGTH,
+ MAX_CLOSED_CAPTION_LENGTH)
+ );
+ }
}
- if (!_too_many_ccap_lines && lines > MAX_CLOSED_CAPTION_LINES) {
+ if (!_too_many_ccap_lines && lines.size() > MAX_CLOSED_CAPTION_LINES) {
hint(fmt::format(_("Some of your closed captions span more than {} lines, so they will be truncated."), MAX_CLOSED_CAPTION_LINES));
_too_many_ccap_lines = true;
}