- av_free_packet(&pkt);
- } while (!frame_finished);
-
- // TODO: Scale down if needed!
- AVPicture pic;
- avpicture_alloc(&pic, PIX_FMT_RGBA, frame->width, frame->height);
- SwsContext *sws_ctx = sws_getContext(frame->width, frame->height,
- (PixelFormat)frame->format, frame->width, frame->height,
- PIX_FMT_RGBA, SWS_BICUBIC, nullptr, nullptr, nullptr);
+ } while (!eof);
+
+ if (!frame_finished) {
+ fprintf(stderr, "%s: Decoder did not output frame.\n", pathname.c_str());
+ return nullptr;
+ }
+
+ uint8_t *pic_data[4] = {nullptr};
+ unique_ptr<uint8_t *, decltype(av_freep)*> pic_data_cleanup(
+ &pic_data[0], av_freep);
+ int linesizes[4];
+ if (av_image_alloc(pic_data, linesizes, frame->width, frame->height, AV_PIX_FMT_RGBA, 1) < 0) {
+ fprintf(stderr, "%s: Could not allocate picture data\n", pathname.c_str());
+ return nullptr;
+ }
+ unique_ptr<SwsContext, decltype(sws_freeContext)*> sws_ctx(
+ sws_getContext(frame->width, frame->height,
+ (AVPixelFormat)frame->format, frame->width, frame->height,
+ AV_PIX_FMT_RGBA, SWS_BICUBIC, nullptr, nullptr, nullptr),
+ sws_freeContext);