]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/lavfutils.c
avutil/hwcontext_vulkan: fix format specifiers for some printed variables
[ffmpeg] / libavfilter / lavfutils.c
index d7de89f4b31000a1b98ffb7f3047f9e36c7718f9..2bc06257c6fa6ef30672c0a0ab374b469f525d36 100644 (file)
  */
 
 #include "libavutil/imgutils.h"
+#include "libavformat/avformat.h"
 #include "lavfutils.h"
 
 int ff_load_image(uint8_t *data[4], int linesize[4],
                   int *w, int *h, enum AVPixelFormat *pix_fmt,
                   const char *filename, void *log_ctx)
 {
-    AVInputFormat *iformat = NULL;
+    const AVInputFormat *iformat = NULL;
     AVFormatContext *format_ctx = NULL;
-    AVCodec *codec;
+    const AVCodec *codec;
     AVCodecContext *codec_ctx = NULL;
     AVCodecParameters *par;
     AVFrame *frame = NULL;
-    int frame_decoded, ret = 0;
+    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,
@@ -88,11 +87,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 +111,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);