[FFmpeg-devel] Small patch for someone to push please

JULIAN GARDNER joolzg at btinternet.com
Fri Aug 15 12:26:40 CEST 2014


In libavfilter/lavfutils.c around line 77 the code is

    if (ret < 0 || !frame_decoded) {
        av_log(log_ctx, AV_LOG_ERROR, "Failed to decode image from file\n");
        goto end;
    }
    ret = 0;

Now this causes a problem if ret>=0 and frame_decoded==0 as you get dropped out of the routine with a failed decode and no width or height.

my changes

    if (ret < 0 || !frame_decoded) {
        av_log(log_ctx, AV_LOG_ERROR, "Failed to decode image from file\n");
+        ret = !frame_decoded ? -1:ret;
        goto end;
    }
    ret = 0;


Maybe not the correct ret value but at least it stops code which checks for an error from trying to do more stuff on the returned data, which wont be valid

This was caught becuase my code which has now started failing


static int load_image(uint8_t **image_data, int *w, int *h, int *stride,
                     const char *filename, void *log_ctx)
{
    int ret;
    enum AVPixelFormat pix_fmt;
    uint8_t *src_data[4], *dst_data[4];
    int src_linesize[4], dst_linesize[4];

    av_log( NULL, AV_LOG_WARNING, "load_image %s\n", filename);

    /* load image from file */
    if ((ret = ff_load_image(src_data, src_linesize, w, h, &pix_fmt, filename, log_ctx)) < 0)
        return ret;

    if ((ret = ff_scale_image(dst_data, dst_linesize, *w, *h, PIXEL_FORMAT,
                              src_data, src_linesize, *w, *h, pix_fmt,
                              log_ctx)) < 0)
        goto end;

    *stride = dst_linesize[0];

    /* copy image_data to a newly allocated array */
    *image_data = av_malloc(*stride * *h);
    if (!*image_data)
        ret = AVERROR(ENOMEM);
    av_image_copy_plane(*image_data, *stride, dst_data[0], dst_linesize[0], *w*4, *h);
end:
    av_free(src_data[0]);
    av_free(dst_data[0]);

    return ret;
}

I dont know why as the pngs are the same, but i get ret=30148 and decode_frame=0, 30148 is the filesize of the PNG.

output from ffmpeg when running my code is sparse even with '-loglevel debug' 


load_image /home/encoder/images/GameNone_640x360.png
[AVIOContext @ 0x7f966802560] Statistics: 30148 bytes read, 0 seeks
Failed to decode image from file 31480 0

Any ideas

joolz



More information about the ffmpeg-devel mailing list