X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fffmpeg_image_proxy.cc;h=9c91d1d87d7d6c60eb883ee346acbb14876bf5ee;hp=c83bebcb54b63a1ec17e842f83c23841c2deb7ec;hb=f515b8daea9d28200be803bb64ff17e9f30343c4;hpb=72b11d5eb036651b6ff68edf3ed270e8fc52960f diff --git a/src/lib/ffmpeg_image_proxy.cc b/src/lib/ffmpeg_image_proxy.cc index c83bebcb5..9c91d1d87 100644 --- a/src/lib/ffmpeg_image_proxy.cc +++ b/src/lib/ffmpeg_image_proxy.cc @@ -84,6 +84,9 @@ int FFmpegImageProxy::avio_read (uint8_t* buffer, int const amount) { int const to_do = min(int64_t(amount), _data.size() - _pos); + if (to_do == 0) { + return AVERROR_EOF; + } memcpy (buffer, _data.data().get() + _pos, to_do); _pos += to_do; return to_do; @@ -110,7 +113,7 @@ FFmpegImageProxy::avio_seek (int64_t const pos, int whence) } pair, int> -FFmpegImageProxy::image (optional, optional) const +FFmpegImageProxy::image (optional) const { boost::mutex::scoped_lock lm (_mutex); @@ -131,8 +134,23 @@ FFmpegImageProxy::image (optional, optional) const av_dict_set (&options, "probesize", raw_convert(5 * 60 * 1000000).c_str(), 0); int e = avformat_open_input (&format_context, 0, 0, &options); + if ((e < 0 && e == AVERROR_INVALIDDATA) || (e >= 0 && format_context->probe_score <= 25)) { + /* Hack to fix loading of .tga files through AVIOContexts (rather then + directly from the file). This code just does enough to allow the + probe code to take a hint from "foo.tga" and so try targa format. + */ + AVInputFormat* f = av_find_input_format ("image2"); + format_context = avformat_alloc_context (); + format_context->pb = avio_context; + format_context->iformat = f; + e = avformat_open_input (&format_context, "foo.tga", f, &options); + } if (e < 0) { - throw OpenFileError (_path->string(), e, true); + if (_path) { + throw OpenFileError (_path->string(), e, OpenFileError::READ); + } else { + boost::throw_exception(DecodeError(String::compose(_("Could not decode image (%1)"), e))); + } } if (avformat_find_stream_info(format_context, 0) < 0) { @@ -167,7 +185,9 @@ FFmpegImageProxy::image (optional, optional) const _image.reset (new Image (frame)); + av_packet_unref (&packet); av_frame_free (&frame); + avcodec_close (codec_context); avformat_close_input (&format_context); av_free (avio_context->buffer); av_free (avio_context);