- shared_ptr<AudioBuffers> trimmed (new AudioBuffers (audio->channels(), audio->frames() - frames));
- trimmed->copy_from (audio.get(), audio->frames() - frames, frames, 0);
-
- audio = trimmed;
- time = 0;
+ /* We will scale the subtitle up to fit _video_container_size */
+ dcp::Size scaled_size (i->rectangle.width * _video_container_size.width, i->rectangle.height * _video_container_size.height);
+
+ /* Then we need a corrective translation, consisting of two parts:
+ *
+ * 1. that which is the result of the scaling of the subtitle by _video_container_size; this will be
+ * rect.x * _video_container_size.width and rect.y * _video_container_size.height.
+ *
+ * 2. that to shift the origin of the scale by subtitle_scale to the centre of the subtitle; this will be
+ * (width_before_subtitle_scale * (1 - subtitle_x_scale) / 2) and
+ * (height_before_subtitle_scale * (1 - subtitle_y_scale) / 2).
+ *
+ * Combining these two translations gives these expressions.
+ */
+
+ all.push_back (
+ PositionImage (
+ i->image->scale (
+ scaled_size,
+ Scaler::from_id ("bicubic"),
+ i->image->pixel_format (),
+ true
+ ),
+ Position<int> (
+ rint (_video_container_size.width * i->rectangle.x),
+ rint (_video_container_size.height * i->rectangle.y)
+ )
+ )
+ );