Allow changes to colours of FFmpeg subtitles (#795).
[dcpomatic.git] / src / lib / player.cc
index 2028758ac8836c0d49a8f809fed7fbded8eaef06..30f36107f231cc05a724df4e380ab147ad69c875 100644 (file)
@@ -222,7 +222,8 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
                property == DCPContentProperty::CAN_BE_PLAYED ||
                property == TextSubtitleContentProperty::TEXT_SUBTITLE_COLOUR ||
                property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE ||
-               property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE_COLOUR
+               property == TextSubtitleContentProperty::TEXT_SUBTITLE_OUTLINE_COLOUR ||
+               property == FFmpegContentProperty::SUBTITLE_STREAM
                ) {
 
                _have_valid_pieces = false;
@@ -373,7 +374,6 @@ Player::get_video (DCPTime time, bool accurate)
        if (!ps.text.empty ()) {
                list<PositionImage> s = render_subtitles (ps.text, ps.fonts, _video_container_size);
                copy (s.begin (), s.end (), back_inserter (sub_images));
-               cout << "got " << s.size() << " text subs rendered to images.\n";
        }
 
        optional<PositionImage> subtitles;
@@ -671,8 +671,17 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt,
                                s.set_v_position (s.v_position() + subtitle_content->subtitle_y_offset ());
                                float const xs = subtitle_content->subtitle_x_scale();
                                float const ys = subtitle_content->subtitle_y_scale();
-                               float const average = s.size() * (xs + ys) / 2;
-                               s.set_size (average);
+                               float size = s.size();
+
+                               /* Adjust size to express the common part of the scaling;
+                                  e.g. if xs = ys = 0.5 we scale size by 2.
+                               */
+                               if (xs > 1e-5 && ys > 1e-5) {
+                                       size *= 1 / min (1 / xs, 1 / ys);
+                               }
+                               s.set_size (size);
+
+                               /* Then express aspect ratio changes */
                                if (fabs (1.0 - xs / ys) > dcp::ASPECT_ADJUST_EPSILON) {
                                        s.set_aspect_adjust (xs / ys);
                                }