vo_image: move to global options

This is a bit "special", because the config tree wants unique
m_sub_options pointers in the whole thing.
This commit is contained in:
wm4 2016-09-05 21:04:55 +02:00
parent 726ef35aa8
commit 9e6b9d8a98
5 changed files with 72 additions and 37 deletions

View File

@ -381,7 +381,9 @@ Available video output drivers are:
Output each frame into an image file in the current directory. Each file
takes the frame number padded with leading zeros as name.
``format=<format>``
The following global options are supported by this video output:
``--vo-image-format=<format>``
Select the image file format.
jpg
@ -399,24 +401,24 @@ Available video output drivers are:
tga
Truevision TGA.
``png-compression=<0-9>``
``--vo-image-png-compression=<0-9>``
PNG compression factor (speed vs. file size tradeoff) (default: 7)
``png-filter=<0-5>``
``--vo-image-png-filter=<0-5>``
Filter applied prior to PNG compression (0 = none; 1 = sub; 2 = up;
3 = average; 4 = Paeth; 5 = mixed) (default: 5)
``jpeg-quality=<0-100>``
``--vo-image-jpeg-quality=<0-100>``
JPEG quality factor (default: 90)
``(no-)jpeg-progressive``
``--vo-image-jpeg-progressive=<yes|no>``
Specify standard or progressive JPEG (default: no).
``(no-)jpeg-baseline``
``--vo-image-jpeg-baseline=<yes|no>``
Specify use of JPEG baseline or not (default: yes).
``jpeg-optimize=<0-100>``
``--vo-image-jpeg-optimize=<0-100>``
JPEG optimization factor (default: 100)
``jpeg-smooth=<0-100>``
``--vo-image-jpeg-smooth=<0-100>``
smooth factor (default: 0)
``jpeg-dpi=<1->``
``--vo-image-jpeg-dpi=<1->``
JPEG DPI (default: 72)
``outdir=<dirname>``
``--vo-image-outdir=<dirname>``
Specify the directory to save the image files to (default: ``./``).
``wayland`` (Wayland only)

View File

@ -40,6 +40,7 @@
#include "stream/stream.h"
#include "video/csputils.h"
#include "video/hwdec.h"
#include "video/image_writer.h"
#include "sub/osd.h"
#include "audio/filter/af.h"
#include "audio/decode/dec_audio.h"
@ -72,7 +73,6 @@ extern const struct m_sub_options vd_lavc_conf;
extern const struct m_sub_options ad_lavc_conf;
extern const struct m_sub_options input_config;
extern const struct m_sub_options encode_config;
extern const struct m_sub_options image_writer_conf;
extern const struct m_sub_options gl_video_conf;
extern const struct m_sub_options ao_alsa_conf;
@ -99,6 +99,12 @@ const struct m_opt_choice_alternatives mp_hwdec_names[] = {
{0}
};
static const struct m_sub_options screenshot_conf = {
.opts = image_writer_opts,
.size = sizeof(struct image_writer_opts),
.defaults = &image_writer_opts_defaults,
};
#define OPT_BASE_STRUCT struct mp_vo_opts
static const m_option_t mp_vo_opt_list[] = {
@ -632,7 +638,7 @@ const m_option_t mp_opts[] = {
OPT_STRING("input-file", input_file, M_OPT_FILE | M_OPT_GLOBAL),
OPT_STRING("input-ipc-server", ipc_path, M_OPT_FILE | M_OPT_FIXED),
OPT_SUBSTRUCT("screenshot", screenshot_image_opts, image_writer_conf, 0),
OPT_SUBSTRUCT("screenshot", screenshot_image_opts, screenshot_conf, 0),
OPT_STRING("screenshot-template", screenshot_template, 0),
OPT_STRING("screenshot-directory", screenshot_directory, 0),

View File

@ -54,20 +54,16 @@ const struct image_writer_opts image_writer_opts_defaults = {
#define OPT_BASE_STRUCT struct image_writer_opts
const struct m_sub_options image_writer_conf = {
.opts = (const m_option_t[]) {
OPT_INTRANGE("jpeg-quality", jpeg_quality, 0, 0, 100),
OPT_INTRANGE("jpeg-smooth", jpeg_smooth, 0, 0, 100),
OPT_FLAG("jpeg-source-chroma", jpeg_source_chroma, 0),
OPT_INTRANGE("png-compression", png_compression, 0, 0, 9),
OPT_INTRANGE("png-filter", png_filter, 0, 0, 5),
OPT_STRING("format", format, 0),
OPT_FLAG("high-bit-depth", high_bit_depth, 0),
OPT_FLAG("tag-colorspace", tag_csp, 0),
{0},
},
.size = sizeof(struct image_writer_opts),
.defaults = &image_writer_opts_defaults,
const struct m_option image_writer_opts[] = {
OPT_INTRANGE("jpeg-quality", jpeg_quality, 0, 0, 100),
OPT_INTRANGE("jpeg-smooth", jpeg_smooth, 0, 0, 100),
OPT_FLAG("jpeg-source-chroma", jpeg_source_chroma, 0),
OPT_INTRANGE("png-compression", png_compression, 0, 0, 9),
OPT_INTRANGE("png-filter", png_filter, 0, 0, 5),
OPT_STRING("format", format, 0),
OPT_FLAG("high-bit-depth", high_bit_depth, 0),
OPT_FLAG("tag-colorspace", tag_csp, 0),
{0},
};
struct image_writer_ctx {

View File

@ -15,6 +15,8 @@
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include "options/m_option.h"
struct mp_image;
struct mp_log;
@ -35,7 +37,7 @@ struct image_writer_opts {
extern const struct image_writer_opts image_writer_opts_defaults;
extern const struct m_sub_options image_writer_conf;
extern const struct m_option image_writer_opts[];
// Return the file extension that will be used, e.g. "png".
const char *image_writer_file_ext(const struct image_writer_opts *opts);

View File

@ -27,6 +27,7 @@
#include "config.h"
#include "misc/bstr.h"
#include "osdep/io.h"
#include "options/m_config.h"
#include "options/path.h"
#include "mpv_talloc.h"
#include "common/common.h"
@ -40,9 +41,30 @@
#include "sub/osd.h"
#include "options/m_option.h"
struct priv {
static const struct m_sub_options image_writer_conf = {
.opts = image_writer_opts,
.size = sizeof(struct image_writer_opts),
.defaults = &image_writer_opts_defaults,
};
struct vo_image_opts {
struct image_writer_opts *opts;
char *outdir;
};
#define OPT_BASE_STRUCT struct vo_image_opts
static const struct m_sub_options vo_image_conf = {
.opts = (const struct m_option[]) {
OPT_SUBSTRUCT("vo-image", opts, image_writer_conf, 0),
OPT_STRING("vo-image-outdir", outdir, 0),
{0},
},
.size = sizeof(struct vo_image_opts),
};
struct priv {
struct vo_image_opts *opts;
struct mp_image *current;
int frame;
@ -92,13 +114,13 @@ static void flip_page(struct vo *vo)
void *t = talloc_new(NULL);
char *filename = talloc_asprintf(t, "%08d.%s", p->frame,
image_writer_file_ext(p->opts));
image_writer_file_ext(p->opts->opts));
if (p->outdir && strlen(p->outdir))
filename = mp_path_join(t, p->outdir, filename);
if (p->opts->outdir && strlen(p->opts->outdir))
filename = mp_path_join(t, p->opts->outdir, filename);
MP_INFO(vo, "Saving %s\n", filename);
write_image(p->current, p->opts, filename, vo->log);
write_image(p->current, p->opts->opts, filename, vo->log);
talloc_free(t);
mp_image_unrefp(&p->current);
@ -121,7 +143,8 @@ static void uninit(struct vo *vo)
static int preinit(struct vo *vo)
{
struct priv *p = vo->priv;
if (p->outdir && !checked_mkdir(vo, p->outdir))
p->opts = mp_get_config_group(vo, vo->global, &vo_image_conf);
if (p->opts->outdir && !checked_mkdir(vo, p->opts->outdir))
return -1;
return 0;
}
@ -131,8 +154,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
return VO_NOTIMPL;
}
#define OPT_BASE_STRUCT struct priv
const struct vo_driver video_out_image =
{
.description = "Write video frames to image files",
@ -140,8 +161,15 @@ const struct vo_driver video_out_image =
.untimed = true,
.priv_size = sizeof(struct priv),
.options = (const struct m_option[]) {
OPT_SUBSTRUCT("", opts, image_writer_conf, 0),
OPT_STRING("outdir", outdir, 0),
OPT_SUBOPT_LEGACY("jpeg-quality", "vo-image-jpeg-quality"),
OPT_SUBOPT_LEGACY("jpeg-smooth", "vo-image-jpeg-smooth"),
OPT_SUBOPT_LEGACY("jpeg-source-chroma", "vo-image-jpeg-source-chroma"),
OPT_SUBOPT_LEGACY("png-compression", "vo-image-png-compression"),
OPT_SUBOPT_LEGACY("png-filter", "vo-image-png-filter"),
OPT_SUBOPT_LEGACY("format", "vo-image-format"),
OPT_SUBOPT_LEGACY("high-bit-depth", "vo-image-high-bit-depth"),
OPT_SUBOPT_LEGACY("tag-colorspace", "vo-image-tag-colorspace"),
OPT_SUBOPT_LEGACY("outdir", "vo-image-outdir"),
{0},
},
.preinit = preinit,
@ -151,4 +179,5 @@ const struct vo_driver video_out_image =
.draw_image = draw_image,
.flip_page = flip_page,
.uninit = uninit,
.global_opts = &vo_image_conf,
};