mirror of https://github.com/mpv-player/mpv
screenshot: show a message on each screenshot taken
The message reads: "Screenshot: filename", where the filename is what mpv passes to fopen(). It will also show error messages when saving the screenshot fails.
This commit is contained in:
parent
f47ead1509
commit
9042552209
|
@ -2166,7 +2166,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
case MP_CMD_SCREENSHOT:
|
case MP_CMD_SCREENSHOT:
|
||||||
screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
|
screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i,
|
||||||
|
!!(cmd->on_osd & MP_ON_OSD_MSG));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_CMD_RUN:
|
case MP_CMD_RUN:
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "core/command.h"
|
#include "core/command.h"
|
||||||
#include "core/bstr.h"
|
#include "core/bstr.h"
|
||||||
#include "core/mp_msg.h"
|
#include "core/mp_msg.h"
|
||||||
|
#include "core/mp_osd.h"
|
||||||
#include "core/path.h"
|
#include "core/path.h"
|
||||||
#include "video/mp_image.h"
|
#include "video/mp_image.h"
|
||||||
#include "video/decode/dec_video.h"
|
#include "video/decode/dec_video.h"
|
||||||
|
@ -47,7 +48,8 @@ typedef struct screenshot_ctx {
|
||||||
struct MPContext *mpctx;
|
struct MPContext *mpctx;
|
||||||
|
|
||||||
int mode;
|
int mode;
|
||||||
int each_frame;
|
bool each_frame;
|
||||||
|
bool osd;
|
||||||
|
|
||||||
int frameno;
|
int frameno;
|
||||||
} screenshot_ctx;
|
} screenshot_ctx;
|
||||||
|
@ -61,6 +63,31 @@ void screenshot_init(struct MPContext *mpctx)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SMSG_OK 0
|
||||||
|
#define SMSG_ERR 1
|
||||||
|
|
||||||
|
static void screenshot_msg(screenshot_ctx *ctx, int status, const char *msg,
|
||||||
|
...) PRINTF_ATTRIBUTE(3,4);
|
||||||
|
|
||||||
|
static void screenshot_msg(screenshot_ctx *ctx, int status, const char *msg,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
va_start(ap, msg);
|
||||||
|
s = talloc_vasprintf(NULL, msg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
mp_msg(MSGT_CPLAYER, status == SMSG_ERR ? MSGL_ERR : MSGL_INFO, "%s\n", s);
|
||||||
|
if (ctx->osd) {
|
||||||
|
set_osd_tmsg(ctx->mpctx, OSD_MSG_TEXT, 1, ctx->mpctx->opts.osd_duration,
|
||||||
|
"%s", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
talloc_free(s);
|
||||||
|
}
|
||||||
|
|
||||||
static char *stripext(void *talloc_ctx, const char *s)
|
static char *stripext(void *talloc_ctx, const char *s)
|
||||||
{
|
{
|
||||||
const char *end = strrchr(s, '.');
|
const char *end = strrchr(s, '.');
|
||||||
|
@ -213,9 +240,9 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
|
||||||
&ctx->frameno);
|
&ctx->frameno);
|
||||||
|
|
||||||
if (!fname) {
|
if (!fname) {
|
||||||
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Invalid screenshot filename "
|
screenshot_msg(ctx, SMSG_ERR, "Invalid screenshot filename "
|
||||||
"template! Fix or remove the --screenshot-template option."
|
"template! Fix or remove the --screenshot-template "
|
||||||
"\n");
|
"option.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,8 +250,8 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
|
||||||
return fname;
|
return fname;
|
||||||
|
|
||||||
if (sequence == prev_sequence) {
|
if (sequence == prev_sequence) {
|
||||||
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Can't save screenshot, file '%s' "
|
screenshot_msg(ctx, SMSG_ERR, "Can't save screenshot, file '%s' "
|
||||||
"already exists!\n", fname);
|
"already exists!", fname);
|
||||||
talloc_free(fname);
|
talloc_free(fname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -263,21 +290,21 @@ static void screenshot_save(struct MPContext *mpctx, struct mp_image *image,
|
||||||
|
|
||||||
char *filename = gen_fname(ctx, image_writer_file_ext(opts));
|
char *filename = gen_fname(ctx, image_writer_file_ext(opts));
|
||||||
if (filename) {
|
if (filename) {
|
||||||
mp_msg(MSGT_CPLAYER, MSGL_INFO, "*** screenshot '%s' ***\n", filename);
|
screenshot_msg(ctx, SMSG_OK, "Screenshot: '%s'", filename);
|
||||||
if (!write_image(image, opts, filename))
|
if (!write_image(image, opts, filename))
|
||||||
mp_msg(MSGT_CPLAYER, MSGL_ERR, "\nError writing screenshot!\n");
|
screenshot_msg(ctx, SMSG_ERR, "Error writing screenshot!");
|
||||||
talloc_free(filename);
|
talloc_free(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
talloc_free(image);
|
talloc_free(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame)
|
void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame,
|
||||||
|
bool osd)
|
||||||
{
|
{
|
||||||
if (mpctx->video_out && mpctx->video_out->config_ok) {
|
if (mpctx->video_out && mpctx->video_out->config_ok) {
|
||||||
screenshot_ctx *ctx = mpctx->screenshot_ctx;
|
screenshot_ctx *ctx = mpctx->screenshot_ctx;
|
||||||
|
|
||||||
|
|
||||||
if (mode == MODE_SUBTITLES && mpctx->osd->render_subs_in_filter)
|
if (mode == MODE_SUBTITLES && mpctx->osd->render_subs_in_filter)
|
||||||
mode = 0;
|
mode = 0;
|
||||||
|
|
||||||
|
@ -290,6 +317,7 @@ void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->mode = mode;
|
ctx->mode = mode;
|
||||||
|
ctx->osd = osd;
|
||||||
|
|
||||||
struct voctrl_screenshot_args args =
|
struct voctrl_screenshot_args args =
|
||||||
{ .full_window = (mode == MODE_FULL_WINDOW) };
|
{ .full_window = (mode == MODE_FULL_WINDOW) };
|
||||||
|
@ -305,8 +333,7 @@ void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame)
|
||||||
mode = 0;
|
mode = 0;
|
||||||
screenshot_save(mpctx, args.out_image, mode == MODE_SUBTITLES);
|
screenshot_save(mpctx, args.out_image, mode == MODE_SUBTITLES);
|
||||||
} else {
|
} else {
|
||||||
mp_msg(MSGT_CPLAYER, MSGL_INFO,
|
screenshot_msg(ctx, SMSG_ERR, "Taking screenshot failed.");
|
||||||
"Taking screenshot failed (need --vf=screenshot?)\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,5 +346,5 @@ void screenshot_flip(struct MPContext *mpctx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ctx->each_frame = false;
|
ctx->each_frame = false;
|
||||||
screenshot_request(mpctx, ctx->mode, true);
|
screenshot_request(mpctx, ctx->mode, true, ctx->osd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,9 @@ void screenshot_init(struct MPContext *mpctx);
|
||||||
// mode: 0: -, 1: save the actual output window contents, 2: with subtitles.
|
// mode: 0: -, 1: save the actual output window contents, 2: with subtitles.
|
||||||
// each_frame: If set, this toggles per-frame screenshots, exactly like the
|
// each_frame: If set, this toggles per-frame screenshots, exactly like the
|
||||||
// screenshot slave command (MP_CMD_SCREENSHOT).
|
// screenshot slave command (MP_CMD_SCREENSHOT).
|
||||||
void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame);
|
// osd: show status on OSD
|
||||||
|
void screenshot_request(struct MPContext *mpctx, int mode, bool each_frame,
|
||||||
|
bool osd);
|
||||||
|
|
||||||
// Called by the playback core code when a new frame is displayed.
|
// Called by the playback core code when a new frame is displayed.
|
||||||
void screenshot_flip(struct MPContext *mpctx);
|
void screenshot_flip(struct MPContext *mpctx);
|
||||||
|
|
Loading…
Reference in New Issue