2012-08-06 15:52:17 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2012-08-06 15:52:47 +00:00
|
|
|
#include <sys/stat.h>
|
2012-08-06 15:52:17 +00:00
|
|
|
|
|
|
|
#include <libswscale/swscale.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/bstr.h"
|
2012-08-06 15:52:47 +00:00
|
|
|
#include "osdep/io.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/path.h"
|
2012-08-06 15:52:17 +00:00
|
|
|
#include "talloc.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "video/out/vo.h"
|
|
|
|
#include "video/csputils.h"
|
|
|
|
#include "video/vfcap.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/fmt-conversion.h"
|
|
|
|
#include "video/image_writer.h"
|
2012-12-22 18:11:53 +00:00
|
|
|
#include "video/sws_utils.h"
|
|
|
|
#include "sub/sub.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/m_option.h"
|
2012-08-06 15:52:17 +00:00
|
|
|
|
|
|
|
struct priv {
|
|
|
|
struct image_writer_opts *opts;
|
2012-08-06 15:52:47 +00:00
|
|
|
char *outdir;
|
2012-08-06 15:52:17 +00:00
|
|
|
|
2012-12-22 18:11:53 +00:00
|
|
|
struct mp_image *current;
|
|
|
|
|
2012-08-06 15:52:17 +00:00
|
|
|
int frame;
|
|
|
|
|
|
|
|
uint32_t d_width;
|
|
|
|
uint32_t d_height;
|
|
|
|
|
|
|
|
struct mp_csp_details colorspace;
|
|
|
|
};
|
|
|
|
|
2012-08-06 15:52:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-06 15:52:17 +00:00
|
|
|
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;
|
|
|
|
|
2012-12-22 18:11:53 +00:00
|
|
|
mp_image_unrefp(&p->current);
|
|
|
|
|
2012-08-06 15:52:17 +00:00
|
|
|
p->d_width = d_width;
|
|
|
|
p->d_height = d_height;
|
|
|
|
|
2012-08-06 15:52:47 +00:00
|
|
|
if (p->outdir && vo->config_count < 1)
|
|
|
|
if (!checked_mkdir(p->outdir))
|
|
|
|
return -1;
|
|
|
|
|
2012-08-06 15:52:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_events(struct vo *vo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-22 18:11:53 +00:00
|
|
|
static void draw_image(struct vo *vo, mp_image_t *mpi)
|
2012-08-06 15:52:17 +00:00
|
|
|
{
|
2012-12-22 18:11:53 +00:00
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
|
|
|
mp_image_setrefp(&p->current, mpi);
|
|
|
|
|
|
|
|
mp_image_set_display_size(p->current, p->d_width, p->d_height);
|
|
|
|
mp_image_set_colorspace_details(p->current, &p->colorspace);
|
2012-08-06 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 18:11:53 +00:00
|
|
|
static void draw_osd(struct vo *vo, struct osd_state *osd)
|
2012-08-06 15:52:17 +00:00
|
|
|
{
|
2012-12-22 18:11:53 +00:00
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
|
|
|
struct aspect_data asp = vo->aspdat;
|
|
|
|
double sar = (double)asp.orgw / asp.orgh;
|
|
|
|
double dar = (double)asp.prew / asp.preh;
|
|
|
|
|
|
|
|
struct mp_osd_res dim = {
|
|
|
|
.w = asp.orgw,
|
|
|
|
.h = asp.orgh,
|
|
|
|
.display_par = sar / dar,
|
|
|
|
.video_par = dar / sar,
|
|
|
|
};
|
|
|
|
|
|
|
|
osd_draw_on_image(osd, dim, osd->vo_pts, OSD_DRAW_SUB_ONLY, p->current);
|
2012-08-06 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 18:11:53 +00:00
|
|
|
static void flip_page(struct vo *vo)
|
2012-08-06 15:52:17 +00:00
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
2012-08-06 15:52:47 +00:00
|
|
|
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);
|
2012-12-22 18:11:53 +00:00
|
|
|
write_image(p->current, p->opts, filename);
|
2012-08-06 15:52:17 +00:00
|
|
|
|
2012-08-06 15:52:47 +00:00
|
|
|
talloc_free(t);
|
2012-12-22 18:11:53 +00:00
|
|
|
mp_image_unrefp(&p->current);
|
2012-08-06 15:52:17 +00:00
|
|
|
|
|
|
|
(p->frame)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vo *vo, uint32_t fmt)
|
|
|
|
{
|
2012-12-22 18:11:53 +00:00
|
|
|
if (mp_sws_supported_format(fmt))
|
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD;
|
2012-08-06 15:52:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct vo *vo)
|
|
|
|
{
|
2012-12-22 18:11:53 +00:00
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
|
|
|
mp_image_unrefp(&p->current);
|
2012-08-06 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int preinit(struct vo *vo, const char *arg)
|
|
|
|
{
|
2012-12-14 11:59:05 +00:00
|
|
|
vo->untimed = true;
|
2012-08-06 15:52:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(struct vo *vo, uint32_t request, void *data)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
|
|
|
switch (request) {
|
|
|
|
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 =
|
|
|
|
{
|
|
|
|
.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),
|
2012-08-06 15:52:47 +00:00
|
|
|
OPT_STRING("outdir", outdir, 0),
|
2012-08-06 15:52:17 +00:00
|
|
|
{0},
|
|
|
|
},
|
|
|
|
.preinit = preinit,
|
2012-11-04 15:24:18 +00:00
|
|
|
.query_format = query_format,
|
2012-08-06 15:52:17 +00:00
|
|
|
.config = config,
|
|
|
|
.control = control,
|
2012-11-04 14:56:04 +00:00
|
|
|
.draw_image = draw_image,
|
2012-08-06 15:52:17 +00:00
|
|
|
.draw_osd = draw_osd,
|
|
|
|
.flip_page = flip_page,
|
|
|
|
.check_events = check_events,
|
|
|
|
.uninit = uninit,
|
|
|
|
};
|