X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fffmpeg_image_proxy.cc;h=00d2a6a59515a60519a6a0e12854016ddaea0ab4;hb=130b03ddabdd5abd5052651aae86ad1955e39ad3;hp=4b3c3084c7f2db4a71c529f88b23f8b7c1e1e7f6;hpb=952084c4221c5708e02c783284cf0f7239c6b4c4;p=dcpomatic.git diff --git a/src/lib/ffmpeg_image_proxy.cc b/src/lib/ffmpeg_image_proxy.cc index 4b3c3084c..00d2a6a59 100644 --- a/src/lib/ffmpeg_image_proxy.cc +++ b/src/lib/ffmpeg_image_proxy.cc @@ -21,21 +21,23 @@ #include "compose.hpp" #include "cross.h" +#include "dcpomatic_assert.h" #include "dcpomatic_socket.h" #include "exceptions.h" #include "ffmpeg_image_proxy.h" #include "image.h" -#include "util.h" -#include "warnings.h" +#include "memory_util.h" +#include "video_filter_graph.h" #include -DCPOMATIC_DISABLE_WARNINGS +#include +LIBDCP_DISABLE_WARNINGS extern "C" { #include #include #include } #include -DCPOMATIC_ENABLE_WARNINGS +LIBDCP_ENABLE_WARNINGS #include #include "i18n.h" @@ -169,7 +171,13 @@ FFmpegImageProxy::image (Image::Alignment alignment, optional) const throw DecodeError (N_("avcodec_find_stream_info"), name_for_errors, r, *_path); } - DCPOMATIC_ASSERT (format_context->nb_streams == 1); + if (format_context->nb_streams != 1) { + if (_path) { + throw DecodeError("FFmpegProxy::image", String::compose("stream count %1", format_context->nb_streams), *_path); + } else { + throw DecodeError("FFmpegProxy::image", String::compose("stream count %1", format_context->nb_streams)); + } + } auto frame = av_frame_alloc (); if (!frame) { @@ -205,7 +213,20 @@ FFmpegImageProxy::image (Image::Alignment alignment, optional) const throw DecodeError (N_("avcodec_receive_frame"), name_for_errors, r, *_path); } - _image = make_shared(frame, alignment); + if (av_pix_fmt_desc_get(context->pix_fmt)->flags & AV_PIX_FMT_FLAG_ALPHA) { + /* XXX: this repeated setup of a the filter graph could be really slow + * (haven't measured it though). + */ + VideoFilterGraph graph(dcp::Size(frame->width, frame->height), context->pix_fmt, dcp::Fraction(24, 1)); + auto filter = Filter::from_id("premultiply"); + DCPOMATIC_ASSERT(filter); + graph.setup({*filter}); + auto images = graph.process(frame); + DCPOMATIC_ASSERT(images.size() == 1); + _image = images.front().first; + } else { + _image = make_shared(frame, alignment); + } av_packet_unref (&packet); av_frame_free (&frame);