From 3041ee8d6c97fbccfe891edad5b57143fb1c6c2a Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 6 Oct 2011 20:46:01 +0200 Subject: 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). --- DOCS/tech/slave.txt | 11 +++++++++-- command.c | 2 +- input/input.c | 4 +++- libvo/video_out.h | 7 +++++++ screenshot.c | 11 +++++++---- screenshot.h | 8 +++++--- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/DOCS/tech/slave.txt b/DOCS/tech/slave.txt index 3b249f75d1..6bb1dc53c4 100644 --- a/DOCS/tech/slave.txt +++ b/DOCS/tech/slave.txt @@ -177,10 +177,17 @@ get_video_codec get_video_resolution Print out the video resolution of the current file. -screenshot +screenshot 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 Inject key code event into MPlayer. diff --git a/command.c b/command.c index 3b77deaa9e..71370e7033 100644 --- a/command.c +++ b/command.c @@ -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: diff --git a/input/input.c b/input/input.c index 7c02be5fa9..e1c001077a 100644 --- a/input/input.c +++ b/input/input.c @@ -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" }, diff --git a/libvo/video_out.h b/libvo/video_out.h index fd61d9c1a1..bd7b2e8fa5 100644 --- a/libvo/video_out.h +++ b/libvo/video_out.h @@ -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 diff --git a/screenshot.c b/screenshot.c index e05bbfe480..9b8c67a89a 100644 --- a/screenshot.c +++ b/screenshot.c @@ -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); } diff --git a/screenshot.h b/screenshot.h index 207d58e003..c57778c0b3 100644 --- a/screenshot.h +++ b/screenshot.h @@ -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. -- cgit v1.2.3