diff --git a/video/image_writer.c b/video/image_writer.c index cff8609ded..d294a4dc32 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -96,12 +96,9 @@ static enum AVPixelFormat replace_j_format(enum AVPixelFormat fmt) static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp) { - bool success = 0; + bool success = false; AVFrame *pic = NULL; - AVPacket pkt = {0}; - int got_output = 0; - - av_init_packet(&pkt); + AVPacket *pkt = NULL; const AVCodec *codec; if (ctx->opts->format == AV_CODEC_ID_WEBP) { @@ -172,18 +169,20 @@ static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp ret = avcodec_send_frame(avctx, NULL); // send EOF if (ret < 0) goto error_exit; - ret = avcodec_receive_packet(avctx, &pkt); + pkt = av_packet_alloc(); + if (!pkt) + goto error_exit; + ret = avcodec_receive_packet(avctx, pkt); if (ret < 0) goto error_exit; - got_output = 1; + success = true; - fwrite(pkt.data, pkt.size, 1, fp); + fwrite(pkt->data, pkt->size, 1, fp); - success = !!got_output; error_exit: avcodec_free_context(&avctx); av_frame_free(&pic); - av_packet_unref(&pkt); + av_packet_free(&pkt); return success; }