summaryrefslogtreecommitdiffstats
path: root/video/image_writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/image_writer.c')
-rw-r--r--video/image_writer.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/video/image_writer.c b/video/image_writer.c
index 0ec949b36a..a65024124e 100644
--- a/video/image_writer.c
+++ b/video/image_writer.c
@@ -86,9 +86,12 @@ struct img_writer {
static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
{
- void *outbuffer = NULL;
int success = 0;
AVFrame *pic = NULL;
+ AVPacket pkt = {0};
+ int got_output = 0;
+
+ av_init_packet(&pkt);
struct AVCodec *codec = avcodec_find_encoder(ctx->writer->lavc_codec);
AVCodecContext *avctx = NULL;
@@ -102,7 +105,7 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
avctx->width = image->w;
avctx->height = image->h;
avctx->pix_fmt = imgfmt2pixfmt(image->imgfmt);
- if (ctx->writer->lavc_codec == CODEC_ID_PNG)
+ if (ctx->writer->lavc_codec == AV_CODEC_ID_PNG)
avctx->compression_level = ctx->opts->png_compression;
if (avcodec_open2(avctx, codec, NULL) < 0) {
@@ -112,11 +115,6 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
goto error_exit;
}
- size_t outbuffer_size = image->w * image->h * 3 * 2;
- outbuffer = malloc(outbuffer_size);
- if (!outbuffer)
- goto error_exit;
-
pic = avcodec_alloc_frame();
if (!pic)
goto error_exit;
@@ -125,19 +123,19 @@ static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
pic->data[n] = image->planes[n];
pic->linesize[n] = image->stride[n];
}
- int size = avcodec_encode_video(avctx, outbuffer, outbuffer_size, pic);
- if (size < 1)
+ int ret = avcodec_encode_video2(avctx, &pkt, pic, &got_output);
+ if (ret < 0)
goto error_exit;
- fwrite(outbuffer, size, 1, fp);
+ fwrite(pkt.data, pkt.size, 1, fp);
- success = 1;
+ success = !!got_output;
error_exit:
if (avctx)
avcodec_close(avctx);
av_free(avctx);
avcodec_free_frame(&pic);
- free(outbuffer);
+ av_free_packet(&pkt);
return success;
}
@@ -210,18 +208,18 @@ static int write_jpeg(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
#endif
static const struct img_writer img_writers[] = {
- { "png", write_lavc, .lavc_codec = CODEC_ID_PNG },
- { "ppm", write_lavc, .lavc_codec = CODEC_ID_PPM },
+ { "png", write_lavc, .lavc_codec = AV_CODEC_ID_PNG },
+ { "ppm", write_lavc, .lavc_codec = AV_CODEC_ID_PPM },
{ "pgm", write_lavc,
- .lavc_codec = CODEC_ID_PGM,
+ .lavc_codec = AV_CODEC_ID_PGM,
.pixfmts = (int[]) { IMGFMT_Y8, 0 },
},
{ "pgmyuv", write_lavc,
- .lavc_codec = CODEC_ID_PGMYUV,
+ .lavc_codec = AV_CODEC_ID_PGMYUV,
.pixfmts = (int[]) { IMGFMT_420P, 0 },
},
{ "tga", write_lavc,
- .lavc_codec = CODEC_ID_TARGA,
+ .lavc_codec = AV_CODEC_ID_TARGA,
.pixfmts = (int[]) { IMGFMT_BGR24, IMGFMT_BGRA, IMGFMT_BGR15_LE,
IMGFMT_Y8, 0},
},
@@ -280,9 +278,8 @@ int write_image(struct mp_image *image, const struct image_writer_opts *opts,
}
}
- // Caveat: - no colorspace/levels conversion done if pixel formats equal
- // - RGB->YUV assumes BT.601
- // - color levels broken in various ways thanks to libswscale
+ // Caveat: no colorspace/levels conversion done if pixel formats equal
+ // it's unclear what colorspace/levels the target wants
if (image->imgfmt != destfmt || is_anamorphic) {
struct mp_image *dst = mp_image_alloc(destfmt, d_w, d_h);
mp_image_copy_attributes(dst, image);