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"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "bstr/bstr.h"
|
2012-08-06 15:52:47 +00:00
|
|
|
#include "osdep/io.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/path.h"
|
2012-08-06 15:52:17 +00:00
|
|
|
#include "talloc.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#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"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "sub/osd.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/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;
|
|
|
|
};
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
static bool checked_mkdir(struct vo *vo, const char *buf)
|
2012-08-06 15:52:47 +00:00
|
|
|
{
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_INFO(vo, "Creating output directory '%s'...\n", buf);
|
2012-08-06 15:52:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_ERR(vo, "Error creating output directory: %s\n", errstr);
|
2012-08-06 15:52:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-24 15:01:42 +00:00
|
|
|
static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
|
2012-08-06 15:52:17 +00:00
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
2012-12-22 18:11:53 +00:00
|
|
|
mp_image_unrefp(&p->current);
|
|
|
|
|
2012-08-06 15:52:47 +00:00
|
|
|
if (p->outdir && vo->config_count < 1)
|
2013-08-23 21:30:09 +00:00
|
|
|
if (!checked_mkdir(vo, p->outdir))
|
2012-08-06 15:52:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-08-06 15:52:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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);
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-05-18 11:19:22 +00:00
|
|
|
(p->frame)++;
|
|
|
|
|
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));
|
|
|
|
|
2013-08-23 21:30:09 +00:00
|
|
|
MP_INFO(vo, "Saving %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
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vo *vo, uint32_t fmt)
|
|
|
|
{
|
2012-12-22 18:11:53 +00:00
|
|
|
if (mp_sws_supported_format(fmt))
|
2013-03-01 10:16:01 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
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
|
|
|
}
|
|
|
|
|
2013-07-22 20:52:42 +00:00
|
|
|
static int preinit(struct vo *vo)
|
2012-08-06 15:52:17 +00:00
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
|
|
|
const struct vo_driver video_out_image =
|
|
|
|
{
|
2013-10-23 17:06:14 +00:00
|
|
|
.description = "Write video frames to image files",
|
|
|
|
.name = "image",
|
2012-08-06 15:52:17 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.options = (const struct m_option[]) {
|
options: drop --opt:subopt option names
For all suboptions, "flat" options were available by separating the
parent option and the sub option with ":", e.g. "--rawvideo:w=123". Drop
this syntax and use "-" as separator. This means even suboptions are
available as normal options now, e.g. "--rawvideo-w=123". The old syntax
doesn't work anymore.
Note that this is completely separate from actual suboptions. For
example, "-rawvideo w=123:h=123" still works. (Not that this syntax is
worth supporting, but it's needed anyway, for for other things like vf
and vo suboptions.)
As a consequence of this change, we also have to add new "no-" prefixed
options for flag suboptions, so that "--no-input-default-bindings"
works. ("--input-no-default-bindings" also works as a consequence of
allowing "-input no-default-bindings" - they are handled by the same
underlying option.)
For --input, always use the full syntax in the manpage. There exist
suboptions other than --input (like --tv, --rawvideo, etc.), but since
they might be handled differently in the future, don't touch these yet.
M_OPT_PREFIXED becomes the default, so remove it. As a minor unrelated
cleanup, get rid of M_OPT_MERGE too and use the OPT_SUBSTRUCT() macro in
some places.
Unrelated: remove the duplicated --tv:buffersize option, fix a typo in
changes.rst.
2013-02-21 21:10:21 +00:00
|
|
|
OPT_SUBSTRUCT("", opts, image_writer_conf, 0),
|
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,
|
2013-08-24 15:01:42 +00:00
|
|
|
.reconfig = reconfig,
|
2012-08-06 15:52:17 +00:00
|
|
|
.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,
|
|
|
|
.uninit = uninit,
|
|
|
|
};
|