Missing include.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index 6e9d671a2fa87792e2ea5b58d6b2d9b2e136822c..45983795b25485f91b4e79dc33339540a28f365e 100644 (file)
@@ -89,7 +89,7 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> film, shared_ptr<const FFmp
                _pts_offset = {};
        }
 
-       if (c->audio) {
+       if (c->has_mapped_audio()) {
                audio = make_shared<AudioDecoder>(this, c->audio, fast);
        }
 
@@ -240,7 +240,7 @@ FFmpegDecoder::pass ()
                decode_and_process_video_packet (packet);
        } else if (fc->subtitle_stream() && fc->subtitle_stream()->uses_index(_format_context, si) && !only_text()->ignore()) {
                decode_and_process_subtitle_packet (packet);
-       } else {
+       } else if (audio) {
                decode_and_process_audio_packet (packet);
        }
 
@@ -668,11 +668,11 @@ FFmpegDecoder::decode_and_process_subtitle_packet (AVPacket* packet)
        */
        ContentTime from;
        from = sub_period.from + _pts_offset;
+       _have_current_subtitle = true;
        if (sub_period.to) {
                _current_subtitle_to = *sub_period.to + _pts_offset;
        } else {
                _current_subtitle_to = optional<ContentTime>();
-               _have_current_subtitle = true;
        }
 
        ContentBitmapText bitmap_text(from);
@@ -720,7 +720,7 @@ FFmpegDecoder::process_bitmap_subtitle (AVSubtitleRect const * rect)
        /* sub_p looks up into a BGRA palette which is at rect->pict.data[1];
           (i.e. first byte B, second G, third R, fourth A)
        */
-       auto const palette = rect->pict.data[1];
+       auto const* palette = rect->pict.data[1];
 #else
        /* Start of the first line in the subtitle */
        auto sub_p = rect->data[0];
@@ -781,11 +781,23 @@ FFmpegDecoder::process_bitmap_subtitle (AVSubtitleRect const * rect)
        if (target_height == 0 && video_codec_context()) {
                target_height = video_codec_context()->height;
        }
-       DCPOMATIC_ASSERT (target_width);
-       DCPOMATIC_ASSERT (target_height);
+
+       int x_offset = 0;
+       int y_offset = 0;
+       if (_ffmpeg_content->video && _ffmpeg_content->video->use()) {
+               auto const crop = _ffmpeg_content->video->actual_crop();
+               target_width -= crop.left + crop.right;
+               target_height -= crop.top + crop.bottom;
+               x_offset = -crop.left;
+               y_offset = -crop.top;
+       }
+
+       DCPOMATIC_ASSERT(target_width > 0);
+       DCPOMATIC_ASSERT(target_height > 0);
+
        dcpomatic::Rect<double> const scaled_rect (
-               static_cast<double>(rect->x) / target_width,
-               static_cast<double>(rect->y) / target_height,
+               static_cast<double>(rect->x + x_offset) / target_width,
+               static_cast<double>(rect->y + y_offset) / target_height,
                static_cast<double>(rect->w) / target_width,
                static_cast<double>(rect->h) / target_height
                );
@@ -816,13 +828,11 @@ FFmpegDecoder::process_ass_subtitle (string ass, ContentTime from)
        }
 
        sub::RawSubtitle base;
-       auto raw = sub::SSAReader::parse_line (
-               base,
-               text,
-               _ffmpeg_content->video->size().width,
-               _ffmpeg_content->video->size().height,
-               sub::Colour(1, 1, 1)
-               );
+       auto video_size = _ffmpeg_content->video->size();
+       DCPOMATIC_ASSERT(video_size);
+
+       sub::SSAReader::Context context(video_size->width, video_size->height, sub::Colour(1, 1, 1));
+       auto const raw = sub::SSAReader::parse_line(base, text, context);
 
        for (auto const& i: sub::collect<vector<sub::Subtitle>>(raw)) {
                only_text()->emit_plain_start (from, i);