X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fffmpeg_image_proxy.cc;h=fa6cb288d28637ece3f55921cf69edb19fe1065e;hb=09063d5958cad17ce89935f38f12c4fcbaaedf4f;hp=46c9836e060d781b1a5083184f052b053812ae08;hpb=dceecebd37d5e1b5c098ad1358310d3f276c703c;p=dcpomatic.git diff --git a/src/lib/ffmpeg_image_proxy.cc b/src/lib/ffmpeg_image_proxy.cc index 46c9836e0..fa6cb288d 100644 --- a/src/lib/ffmpeg_image_proxy.cc +++ b/src/lib/ffmpeg_image_proxy.cc @@ -134,8 +134,23 @@ FFmpegImageProxy::image (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, true); + } else { + boost::throw_exception(DecodeError(String::compose(_("Could not decode image (%1)"), e))); + } } if (avformat_find_stream_info(format_context, 0) < 0) {