summaryrefslogtreecommitdiffstats
path: root/video/out/vo_image.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-05 17:02:04 +0100
committerwm4 <wm4@nowhere>2012-11-12 20:06:14 +0100
commitd4bdd0473d6f43132257c9fb3848d829755167a3 (patch)
tree8021c2f7da1841393c8c832105e20cd527826d6c /video/out/vo_image.c
parentbd48deba77bd5582c5829d6fe73a7d2571088aba (diff)
downloadmpv-d4bdd0473d6f43132257c9fb3848d829755167a3.tar.bz2
mpv-d4bdd0473d6f43132257c9fb3848d829755167a3.tar.xz
Rename directories, move files (step 1 of 2) (does not compile)
Tis drops the silly lib prefixes, and attempts to organize the tree in a more logical way. Make the top-level directory less cluttered as well. Renames the following directories: libaf -> audio/filter libao2 -> audio/out libvo -> video/out libmpdemux -> demux Split libmpcodecs: vf* -> video/filter vd*, dec_video.* -> video/decode mp_image*, img_format*, ... -> video/ ad*, dec_audio.* -> audio/decode libaf/format.* is moved to audio/ - this is similar to how mp_image.* is located in video/. Move most top-level .c/.h files to core. (talloc.c/.h is left on top- level, because it's external.) Park some of the more annoying files in compat/. Some of these are relicts from the time mplayer used ffmpeg internals. sub/ is not split, because it's too much of a mess (subtitle code is mixed with OSD display and rendering). Maybe the organization of core is not ideal: it mixes playback core (like mplayer.c) and utility helpers (like bstr.c/h). Should the need arise, the playback core will be moved somewhere else, while core contains all helper and common code.
Diffstat (limited to 'video/out/vo_image.c')
-rw-r--r--video/out/vo_image.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/video/out/vo_image.c b/video/out/vo_image.c
new file mode 100644
index 0000000000..7f80a16f35
--- /dev/null
+++ b/video/out/vo_image.c
@@ -0,0 +1,198 @@
+/*
+ * 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 <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"
+#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;
+ char *outdir;
+
+ int frame;
+
+ uint32_t d_width;
+ uint32_t d_height;
+
+ 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)
+{
+ struct priv *p = vo->priv;
+
+ 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;
+}
+
+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 img = *mpi;
+ img.width = p->d_width;
+ img.height = p->d_height;
+ mp_image_set_colorspace_details(&img, &p->colorspace);
+
+ 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->opts, filename);
+
+ talloc_free(t);
+
+ (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),
+ OPT_STRING("outdir", outdir, 0),
+ {0},
+ },
+ .preinit = preinit,
+ .config = config,
+ .control = control,
+ .draw_osd = draw_osd,
+ .flip_page = flip_page,
+ .check_events = check_events,
+ .uninit = uninit,
+};