Fix incorrect reel numbers in subtitle XML/MXF.
[dcpomatic.git] / src / lib / reel_writer.cc
index 2c74d66bdb664fb2ee4950fd07204349ace269e6..8334dc4772d3208e6b95af6fd46f8aeb19136ec7 100644 (file)
@@ -41,6 +41,7 @@
 #include <dcp/certificate_chain.h>
 #include <dcp/interop_subtitle_asset.h>
 #include <dcp/smpte_subtitle_asset.h>
+#include <dcp/raw_convert.h>
 #include <boost/foreach.hpp>
 
 #include "i18n.h"
@@ -57,6 +58,7 @@ using boost::shared_ptr;
 using boost::optional;
 using boost::dynamic_pointer_cast;
 using dcp::Data;
+using dcp::raw_convert;
 
 int const ReelWriter::_info_size = 48;
 
@@ -361,7 +363,12 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
        LOG_GENERAL ("create_reel for %1-%2; %3 of %4", _period.from.get(), _period.to.get(), _reel_index, _reel_count);
 
        DCPOMATIC_ASSERT (reel_picture_asset);
-       DCPOMATIC_ASSERT (reel_picture_asset->duration() == _period.duration().frames_round (_film->video_frame_rate ()));
+       if (reel_picture_asset->duration() != _period.duration().frames_round (_film->video_frame_rate ())) {
+               throw ProgrammingError (
+                       __FILE__, __LINE__,
+                       String::compose ("%1 vs %2", reel_picture_asset->duration(), _period.duration().frames_round (_film->video_frame_rate ()))
+                       );
+       }
        reel->add (reel_picture_asset);
 
        /* If we have a hash for this asset in the CPL, assume that it is correct */
@@ -516,14 +523,14 @@ ReelWriter::write (PlayerSubtitles subs)
                        shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset ());
                        s->set_movie_title (_film->name ());
                        s->set_language (lang);
-                       s->set_reel_number ("1");
+                       s->set_reel_number (raw_convert<string> (_reel_index + 1));
                        _subtitle_asset = s;
                } else {
                        shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
                        s->set_content_title_text (_film->name ());
                        s->set_language (lang);
                        s->set_edit_rate (dcp::Fraction (_film->video_frame_rate (), 1));
-                       s->set_reel_number (1);
+                       s->set_reel_number (_reel_index + 1);
                        s->set_time_code_rate (_film->video_frame_rate ());
                        s->set_start_time (dcp::Time ());
                        if (_film->encrypted ()) {