summaryrefslogtreecommitdiffstats
path: root/image_writer.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-06 17:49:37 +0200
committerwm4 <wm4@nowhere>2012-08-06 17:49:37 +0200
commitc74afab393373d7988983fdd02dd2001c7812483 (patch)
treee9a5e89fc14341aa5374b73801f5be413cb2481c /image_writer.c
parent5f57d276562c18ce65c47fa60f442ea427d7033e (diff)
downloadmpv-c74afab393373d7988983fdd02dd2001c7812483.tar.bz2
mpv-c74afab393373d7988983fdd02dd2001c7812483.tar.xz
image_writer: add some PNM family image formats
While the PNM formats are not that useful, supporting them helps getting rid of vo_pnm. This makes use of the libavcodec PNM encoder. Compared to vo_pnm, at least PNM ASCII mode is not supported. It doesn't look like libavcodec supports this mode for encoding.
Diffstat (limited to 'image_writer.c')
-rw-r--r--image_writer.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/image_writer.c b/image_writer.c
index 750dd15426..f453748c08 100644
--- a/image_writer.c
+++ b/image_writer.c
@@ -74,31 +74,33 @@ struct img_writer {
const char *file_ext;
int (*write)(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp);
int *pixfmts;
+ int lavc_codec;
};
-static int write_png(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
+static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp)
{
void *outbuffer = NULL;
int success = 0;
AVFrame *pic = NULL;
- struct AVCodec *png_codec = avcodec_find_encoder(CODEC_ID_PNG);
+ struct AVCodec *codec = avcodec_find_encoder(ctx->writer->lavc_codec);
AVCodecContext *avctx = NULL;
- if (!png_codec)
+ if (!codec)
goto print_open_fail;
- avctx = avcodec_alloc_context3(png_codec);
+ avctx = avcodec_alloc_context3(codec);
if (!avctx)
goto print_open_fail;
avctx->time_base = AV_TIME_BASE_Q;
avctx->width = image->width;
avctx->height = image->height;
- avctx->pix_fmt = PIX_FMT_RGB24;
- avctx->compression_level = ctx->opts->png_compression;
+ avctx->pix_fmt = imgfmt2pixfmt(image->imgfmt);
+ if (ctx->writer->lavc_codec == CODEC_ID_PNG)
+ avctx->compression_level = ctx->opts->png_compression;
- if (avcodec_open2(avctx, png_codec, NULL) < 0) {
+ if (avcodec_open2(avctx, codec, NULL) < 0) {
print_open_fail:
- mp_msg(MSGT_CPLAYER, MSGL_INFO, "Could not open libavcodec PNG encoder"
+ mp_msg(MSGT_CPLAYER, MSGL_INFO, "Could not open libavcodec encoder"
" for saving images\n");
goto error_exit;
}
@@ -188,7 +190,16 @@ 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_png },
+ { "png", write_lavc, .lavc_codec = CODEC_ID_PNG },
+ { "ppm", write_lavc, .lavc_codec = CODEC_ID_PPM },
+ { "pgm", write_lavc,
+ .lavc_codec = CODEC_ID_PGM,
+ .pixfmts = (int[]) { IMGFMT_Y800, 0 },
+ },
+ { "pgmyuv", write_lavc,
+ .lavc_codec = CODEC_ID_PGMYUV,
+ .pixfmts = (int[]) { IMGFMT_YV12, 0 },
+ },
#ifdef CONFIG_JPEG
{ "jpg", write_jpeg },
{ "jpeg", write_jpeg },