video/image_writer: check for write errors

make sure that fwrite is error checked. and if any data was still
remaining on the buffer, it will be flushed - and errors checked - via
the fclose() call below.
This commit is contained in:
NRK 2023-07-10 18:03:58 +06:00 committed by sfan5
parent 6b76000f0b
commit dc06dec1ee
1 changed files with 2 additions and 3 deletions

View File

@ -127,7 +127,7 @@ static enum AVPixelFormat replace_j_format(enum AVPixelFormat fmt)
static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, const char *filename)
{
FILE* fp = fopen(filename, "wb");
FILE *fp = fopen(filename, "wb");
if (!fp) {
MP_ERR(ctx, "Error opening '%s' for writing!\n", filename);
return false;
@ -229,9 +229,8 @@ static bool write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, const ch
ret = avcodec_receive_packet(avctx, pkt);
if (ret < 0)
goto error_exit;
success = true;
fwrite(pkt->data, pkt->size, 1, fp);
success = fwrite(pkt->data, pkt->size, 1, fp) == 1;
error_exit:
avcodec_free_context(&avctx);