Some boost::filesystem::path cleanups; tweak for changes to libdcp.
[dcpomatic.git] / src / lib / player.cc
index f8ccb0142af5d3a95bdb03f4a965971049f50825..70d6fa8773a445977da35edd2d2b286a042221dd 100644 (file)
@@ -250,12 +250,15 @@ Player::process_video (weak_ptr<Piece> weak_piece, shared_ptr<const Image> image
        if (content->trimmed (relative_time)) {
                return;
        }
-       
-       shared_ptr<Image> work_image = image->crop (content->crop(), true);
+
+       /* Convert to RGB first, as FFmpeg doesn't seem to like handling YUV images with odd widths */
+       shared_ptr<Image> work_image = image->scale (image->size (), _film->scaler(), PIX_FMT_RGB24, true);
+
+       work_image = work_image->crop (content->crop(), true);
 
        libdcp::Size const image_size = content->ratio()->size (_video_container_size);
        
-       work_image = work_image->scale_and_convert_to_rgb (image_size, _film->scaler(), true);
+       work_image = work_image->scale (image_size, _film->scaler(), PIX_FMT_RGB24, true);
 
        Time time = content->position() + relative_time - content->trim_start ();
            
@@ -300,6 +303,13 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
        shared_ptr<AudioContent> content = dynamic_pointer_cast<AudioContent> (piece->content);
        assert (content);
 
+       /* Gain */
+       if (content->audio_gain() != 0) {
+               shared_ptr<AudioBuffers> gain (new AudioBuffers (audio));
+               gain->apply_gain (content->audio_gain ());
+               audio = gain;
+       }
+
        /* Resample */
        if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) {
                shared_ptr<Resampler> r = resampler (content, true);
@@ -557,6 +567,10 @@ Player::emit_black ()
 void
 Player::emit_silence (OutputAudioFrame most)
 {
+       if (most == 0) {
+               return;
+       }
+       
        OutputAudioFrame N = min (most, _film->audio_frame_rate() / 2);
        shared_ptr<AudioBuffers> silence (new AudioBuffers (_film->audio_channels(), N));
        silence->make_silent ();
@@ -629,7 +643,12 @@ Player::update_subtitle ()
        _out_subtitle.position.x = rint (_video_container_size.width * (in_rect.x + (in_rect.width * (1 - sc->subtitle_scale ()) / 2)));
        _out_subtitle.position.y = rint (_video_container_size.height * (in_rect.y + (in_rect.height * (1 - sc->subtitle_scale ()) / 2)));
        
-       _out_subtitle.image = _in_subtitle.image->scale (libdcp::Size (scaled_size.width, scaled_size.height), Scaler::from_id ("bicubic"), true);
+       _out_subtitle.image = _in_subtitle.image->scale (
+               scaled_size,
+               Scaler::from_id ("bicubic"),
+               _in_subtitle.image->pixel_format (),
+               true
+               );
        _out_subtitle.from = _in_subtitle.from + piece->content->position ();
        _out_subtitle.to = _in_subtitle.to + piece->content->position ();
 }