diff options
author | wm4 <wm4@nowhere> | 2012-08-06 17:52:17 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-08-06 17:52:17 +0200 |
commit | c7b66d99d1830685ec3761ebf0a3625dee69f5d1 (patch) | |
tree | b932c03a1c892694fdd207b88104bbafe26369e5 | |
parent | b43adea6c850a3f8e8660428cfa4875e3d698ea6 (diff) | |
download | mpv-c7b66d99d1830685ec3761ebf0a3625dee69f5d1.tar.bz2 mpv-c7b66d99d1830685ec3761ebf0a3625dee69f5d1.tar.xz |
vo_image: add new video output for writing images
This is supposed to replace vo_png and others.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | libvo/video_out.c | 7 | ||||
-rw-r--r-- | libvo/video_out.h | 3 | ||||
-rw-r--r-- | libvo/vo_image.c | 163 |
4 files changed, 173 insertions, 1 deletions
@@ -432,6 +432,7 @@ SRCS_MPLAYER = command.c \ libvo/video_out.c \ libvo/vo_null.c \ libvo/vo_png.c \ + libvo/vo_image.c \ $(SRCS_MPLAYER-yes) COMMON_LIBS += $(COMMON_LIBS-yes) diff --git a/libvo/video_out.c b/libvo/video_out.c index 5dad7e2be4..c453907272 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -82,6 +82,7 @@ extern struct vo_driver video_out_gl; extern struct vo_driver video_out_gl3; extern struct vo_driver video_out_null; extern struct vo_driver video_out_png; +extern struct vo_driver video_out_image; extern struct vo_driver video_out_caca; extern struct vo_driver video_out_yuv4mpeg; extern struct vo_driver video_out_direct3d; @@ -146,6 +147,7 @@ const struct vo_driver *video_out_drivers[] = &video_out_yuv4mpeg, #endif &video_out_png, + &video_out_image, #ifdef CONFIG_JPEG &video_out_jpeg, #endif @@ -172,8 +174,11 @@ const struct vo_driver *video_out_drivers[] = static int vo_preinit(struct vo *vo, char *arg) { - if (vo->driver->priv_size) + if (vo->driver->priv_size) { vo->priv = talloc_zero_size(vo, vo->driver->priv_size); + if (vo->driver->priv_defaults) + memcpy(vo->priv, vo->driver->priv_defaults, vo->driver->priv_size); + } if (vo->driver->options) { struct m_config *cfg = m_config_simple(vo->priv); talloc_steal(vo->priv, cfg); diff --git a/libvo/video_out.h b/libvo/video_out.h index 2bcb15bd4c..6cc7c0d02f 100644 --- a/libvo/video_out.h +++ b/libvo/video_out.h @@ -232,6 +232,9 @@ struct vo_driver { // Size of private struct for automatic allocation (0 doesn't allocate) int priv_size; + // If not NULL, it's copied into the newly allocated private struct. + const void *priv_defaults; + // List of options to parse into priv struct (requires privsize to be set) const struct m_option *options; }; diff --git a/libvo/vo_image.c b/libvo/vo_image.c new file mode 100644 index 0000000000..8830c41e26 --- /dev/null +++ b/libvo/vo_image.c @@ -0,0 +1,163 @@ +/* + * This file is part of mplayer. + * + * mplayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mplayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mplayer. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <stdbool.h> + +#include <libswscale/swscale.h> + +#include "config.h" +#include "talloc.h" +#include "mp_msg.h" +#include "libvo/video_out.h" +#include "libvo/csputils.h" +#include "libmpcodecs/vfcap.h" +#include "libmpcodecs/mp_image.h" +#include "fmt-conversion.h" +#include "image_writer.h" +#include "m_config.h" +#include "m_option.h" + +struct priv { + struct image_writer_opts *opts; + + int frame; + + uint32_t d_width; + uint32_t d_height; + + struct mp_csp_details colorspace; +}; + +static int config(struct vo *vo, uint32_t width, uint32_t height, + uint32_t d_width, uint32_t d_height, uint32_t flags, + uint32_t format) +{ + struct priv *p = vo->priv; + + p->d_width = d_width; + p->d_height = d_height; + + return 0; +} + +static void check_events(struct vo *vo) +{ +} + +static void draw_osd(struct vo *vo, struct osd_state *osd) +{ +} + +static void flip_page(struct vo *vo) +{ +} + +static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) +{ + struct priv *p = vo->priv; + + mp_image_t tmp = *mpi; + tmp.width = p->d_width; + tmp.height = p->d_height; + + char filename[80]; + snprintf(filename, sizeof(filename), "%08d.%s", p->frame, + image_writer_file_ext(p->opts)); + mp_msg(MSGT_VO, MSGL_STATUS, "Save %s!\n", filename); + write_image(&tmp, &p->colorspace, p->opts, filename); + + (p->frame)++; + + return VO_TRUE; +} + +static int query_format(struct vo *vo, uint32_t fmt) +{ + enum PixelFormat av_format = imgfmt2pixfmt(fmt); + + // NOTE: accept everything that can be converted by swscale. screenshot.c + // always wants RGB (at least for now), but it probably doesn't matter + // whether we or screenshot.c do the conversion. + if (av_format != PIX_FMT_NONE && sws_isSupportedInput(av_format)) + return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | + VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; + return 0; +} + +static void uninit(struct vo *vo) +{ +} + +static int preinit(struct vo *vo, const char *arg) +{ + return 0; +} + +static int control(struct vo *vo, uint32_t request, void *data) +{ + struct priv *p = vo->priv; + + switch (request) { + case VOCTRL_QUERY_FORMAT: + return query_format(vo, *(uint32_t *)data); + case VOCTRL_DRAW_IMAGE: + return draw_image(vo, data); + case VOCTRL_SET_YUV_COLORSPACE: + p->colorspace = *(struct mp_csp_details *)data; + return true; + case VOCTRL_GET_YUV_COLORSPACE: + *(struct mp_csp_details *)data = p->colorspace; + return true; + // prevent random frame stepping by frontend + case VOCTRL_REDRAW_FRAME: + return true; + } + return VO_NOTIMPL; +} + +#undef OPT_BASE_STRUCT +#define OPT_BASE_STRUCT struct priv + +const struct vo_driver video_out_image = +{ + .is_new = true, + .info = &(const vo_info_t) { + "Write video frames to image files", + "image", + "wm4", + "" + }, + .priv_size = sizeof(struct priv), + .priv_defaults = &(const struct priv) { + .colorspace = MP_CSP_DETAILS_DEFAULTS, + }, + .options = (const struct m_option[]) { + OPT_SUBSTRUCT(opts, image_writer_conf, M_OPT_MERGE), + {0}, + }, + .preinit = preinit, + .config = config, + .control = control, + .draw_osd = draw_osd, + .flip_page = flip_page, + .check_events = check_events, + .uninit = uninit, +}; |