X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Flavfutils.c;h=f8f8415c80a78ba27db372065cbc19b511e41363;hb=eed2125f3f1762f940bb42d49ae608b90a7f79ae;hp=db4b69b9f36d0a18e1531defd2851e869db894a8;hpb=73d193d1d0ff62a029a905d1404c0fd357f4c880;p=ffmpeg diff --git a/libavfilter/lavfutils.c b/libavfilter/lavfutils.c index db4b69b9f36..f8f8415c80a 100644 --- a/libavfilter/lavfutils.c +++ b/libavfilter/lavfutils.c @@ -27,16 +27,14 @@ int ff_load_image(uint8_t *data[4], int linesize[4], { AVInputFormat *iformat = NULL; AVFormatContext *format_ctx = NULL; - AVCodec *codec; - AVCodecContext *codec_ctx; + const AVCodec *codec; + AVCodecContext *codec_ctx = NULL; AVCodecParameters *par; - AVFrame *frame; - int frame_decoded, ret = 0; + AVFrame *frame = NULL; + int ret = 0; AVPacket pkt; AVDictionary *opt=NULL; - av_init_packet(&pkt); - iformat = av_find_input_format("image2pipe"); if ((ret = avformat_open_input(&format_ctx, filename, iformat, NULL)) < 0) { av_log(log_ctx, AV_LOG_ERROR, @@ -46,7 +44,7 @@ int ff_load_image(uint8_t *data[4], int linesize[4], if ((ret = avformat_find_stream_info(format_ctx, NULL)) < 0) { av_log(log_ctx, AV_LOG_ERROR, "Find stream info failed\n"); - return ret; + goto end; } par = format_ctx->streams[0]->codecpar; @@ -88,11 +86,16 @@ int ff_load_image(uint8_t *data[4], int linesize[4], goto end; } - ret = avcodec_decode_video2(codec_ctx, frame, &frame_decoded, &pkt); - if (ret < 0 || !frame_decoded) { + ret = avcodec_send_packet(codec_ctx, &pkt); + av_packet_unref(&pkt); + if (ret < 0) { + av_log(log_ctx, AV_LOG_ERROR, "Error submitting a packet to decoder\n"); + goto end; + } + + ret = avcodec_receive_frame(codec_ctx, frame); + if (ret < 0) { av_log(log_ctx, AV_LOG_ERROR, "Failed to decode image from file\n"); - if (ret >= 0) - ret = -1; goto end; } @@ -107,7 +110,6 @@ int ff_load_image(uint8_t *data[4], int linesize[4], av_image_copy(data, linesize, (const uint8_t **)frame->data, frame->linesize, *pix_fmt, *w, *h); end: - av_packet_unref(&pkt); avcodec_free_context(&codec_ctx); avformat_close_input(&format_ctx); av_frame_free(&frame);