1
mirror of https://github.com/mpv-player/mpv synced 2025-01-16 22:37:28 +01:00

core: add screenshot mode for actual VO window contents

The screenshot command normally converts the currently displayed video
frame to an image. Add support for an alternative screenshot mode
that is supposed to capture the real window contents. Such a
screenshot contains a possibly scaled version of the frame, the OSD,
and subtitles.

Add a default key binding Alt+s for taking screenshots in this mode.

This needs special VO support, and might not work with all VOs (this
commit does not yet contain an implementation for any VO, only the
infrastructure).
This commit is contained in:
wm4 2011-10-06 20:46:01 +02:00 committed by Uoti Urpala
parent 01cf896a2f
commit 3041ee8d6c
6 changed files with 32 additions and 11 deletions

View File

@ -177,10 +177,17 @@ get_video_codec
get_video_resolution
Print out the video resolution of the current file.
screenshot <value>
screenshot <each_frame> <full_window>
Take a screenshot. Requires the screenshot filter to be loaded.
0 Take a single screenshot.
each_frame:
0 Take a single screenshot. (Default.)
1 Start/stop taking screenshot of each frame.
full_window:
0 Save the video image, in its original resolution. Typically without
OSD or subtitles. (Default.)
1 Save the contents of the mplayer window. Typically with OSD and
subtitles. If not available (no VO support), this may act as if 0 was
passed.
key_down_event <value>
Inject <value> key code event into MPlayer.

View File

@ -3381,7 +3381,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
break;
case MP_CMD_SCREENSHOT:
screenshot_request(mpctx, cmd->args[0].v.i);
screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
break;
case MP_CMD_VF_CHANGE_RECTANGLE:

View File

@ -176,7 +176,7 @@ static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_VO_ONTOP, "vo_ontop", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_VO_ROOTWIN, "vo_rootwin", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_VO_BORDER, "vo_border", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
{ MP_CMD_SCREENSHOT, "screenshot", 0, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_SCREENSHOT, "screenshot", 0, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_PANSCAN, "panscan",1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_SWITCH_VSYNC, "switch_vsync", 0, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_LOADFILE, "loadfile", 1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
@ -507,6 +507,8 @@ static const struct cmd_bind def_cmd_binds[] = {
{ { 'C', 0 }, "step_property_osd capturing" },
{ { 's', 0 }, "screenshot 0" },
{ { 'S', 0 }, "screenshot 1" },
{ { KEY_MODIFIER_ALT + 's', 0 }, "screenshot 0 1" },
{ { KEY_MODIFIER_ALT + 'S', 0 }, "screenshot 1 1" },
{ { 'w', 0 }, "panscan -0.1" },
{ { 'e', 0 }, "panscan +0.1" },

View File

@ -108,6 +108,13 @@ typedef struct mp_eosd_res {
// VOCTRL_SCREENSHOT
struct voctrl_screenshot_args {
// 0: Save image of the currently displayed video frame, in original
// resolution.
// 1: Save full screenshot of the window. Should contain OSD, EOSD, and the
// scaled video.
// The value of this variable can be ignored if only a single method is
// implemented.
int full_window;
// Will be set to a newly allocated image, that contains the screenshot.
// The caller has to free the pointer with free_mp_image().
// It is not specified whether the image data is a copy or references the

View File

@ -46,6 +46,7 @@
#include "libvo/csputils.h"
typedef struct screenshot_ctx {
int full_window;
int each_frame;
int using_vf_screenshot;
@ -175,10 +176,11 @@ static void vf_screenshot_callback(void *pctx, struct mp_image *image)
screenshot_ctx *ctx = screenshot_get_ctx(mpctx);
screenshot_save(mpctx, image);
if (ctx->each_frame)
screenshot_request(mpctx, 0);
screenshot_request(mpctx, 0, ctx->full_window);
}
void screenshot_request(struct MPContext *mpctx, bool each_frame)
void screenshot_request(struct MPContext *mpctx, bool each_frame,
bool full_window)
{
if (mpctx->video_out && mpctx->video_out->config_ok) {
screenshot_ctx *ctx = screenshot_get_ctx(mpctx);
@ -187,11 +189,12 @@ void screenshot_request(struct MPContext *mpctx, bool each_frame)
if (each_frame) {
ctx->each_frame = !ctx->each_frame;
ctx->full_window = full_window;
if (!ctx->each_frame)
return;
}
struct voctrl_screenshot_args args;
struct voctrl_screenshot_args args = { .full_window = full_window };
if (vo_control(mpctx->video_out, VOCTRL_SCREENSHOT, &args) == true) {
screenshot_save(mpctx, args.out_image);
free_mp_image(args.out_image);
@ -226,5 +229,5 @@ void screenshot_flip(struct MPContext *mpctx)
if (ctx->using_vf_screenshot)
return;
screenshot_request(mpctx, 0);
screenshot_request(mpctx, 0, ctx->full_window);
}

View File

@ -25,9 +25,11 @@ struct MPContext;
struct mp_image;
// Request a taking & saving a screenshot of the currently displayed frame.
// If each_frame is set, this toggles per-frame screenshots, exactly like the
// screenshot slave command (MP_CMD_SCREENSHOT).
void screenshot_request(struct MPContext *mpctx, bool each_frame);
// each_frame: If set, this toggles per-frame screenshots, exactly like the
// screenshot slave command (MP_CMD_SCREENSHOT).
// full_window: If set, save the actual output window contents.
void screenshot_request(struct MPContext *mpctx, bool each_frame,
bool full_window);
// Save the screenshot contained in the image to disk.
// The image can be in any format supported by libswscale.