summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-06 17:52:47 +0200
committerwm4 <wm4@nowhere>2012-08-06 17:52:47 +0200
commiteb1182eb501d62eb8533ba8379323481ade013db (patch)
treefa43d6e2ac44248972c1e29d8b6788ee9c5a4f0b
parentc7b66d99d1830685ec3761ebf0a3625dee69f5d1 (diff)
downloadmpv-eb1182eb501d62eb8533ba8379323481ade013db.tar.bz2
mpv-eb1182eb501d62eb8533ba8379323481ade013db.tar.xz
vo_image: add outdir option
The function checked_mkdir is taken from vo_jpeg, with the error handling stripped down to a reasonable level.
-rw-r--r--libvo/vo_image.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/libvo/vo_image.c b/libvo/vo_image.c
index 8830c41e26..b00ee1af8f 100644
--- a/libvo/vo_image.c
+++ b/libvo/vo_image.c
@@ -20,10 +20,14 @@
#include <string.h>
#include <math.h>
#include <stdbool.h>
+#include <sys/stat.h>
#include <libswscale/swscale.h>
#include "config.h"
+#include "bstr.h"
+#include "osdep/io.h"
+#include "path.h"
#include "talloc.h"
#include "mp_msg.h"
#include "libvo/video_out.h"
@@ -37,6 +41,7 @@
struct priv {
struct image_writer_opts *opts;
+ char *outdir;
int frame;
@@ -46,6 +51,24 @@ struct priv {
struct mp_csp_details colorspace;
};
+static bool checked_mkdir(const char *buf)
+{
+ mp_msg(MSGT_VO, MSGL_INFO, "[vo_image] Creating output directory '%s'...\n",
+ buf);
+ if (mkdir(buf, 0755) < 0) {
+ char *errstr = strerror(errno);
+ if (errno == EEXIST) {
+ struct stat stat_p;
+ if (mp_stat(buf, &stat_p ) == 0 && S_ISDIR(stat_p.st_mode))
+ return true;
+ }
+ mp_msg(MSGT_VO, MSGL_ERR, "[vo_image] Error creating output directory"
+ ": %s\n", errstr);
+ return false;
+ }
+ return true;
+}
+
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)
@@ -55,6 +78,10 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
p->d_width = d_width;
p->d_height = d_height;
+ if (p->outdir && vo->config_count < 1)
+ if (!checked_mkdir(p->outdir))
+ return -1;
+
return 0;
}
@@ -74,15 +101,21 @@ 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;
+ mp_image_t img = *mpi;
+ img.width = p->d_width;
+ img.height = p->d_height;
+
+ void *t = talloc_new(NULL);
+ char *filename = talloc_asprintf(t, "%08d.%s", p->frame,
+ image_writer_file_ext(p->opts));
+
+ if (p->outdir && strlen(p->outdir))
+ filename = mp_path_join(t, bstr0(p->outdir), bstr0(filename));
+
+ mp_msg(MSGT_VO, MSGL_STATUS, "\nSaving %s\n", filename);
+ write_image(&img, &p->colorspace, p->opts, filename);
- 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);
+ talloc_free(t);
(p->frame)++;
@@ -151,6 +184,7 @@ const struct vo_driver video_out_image =
},
.options = (const struct m_option[]) {
OPT_SUBSTRUCT(opts, image_writer_conf, M_OPT_MERGE),
+ OPT_STRING("outdir", outdir, 0),
{0},
},
.preinit = preinit,