2011-10-06 18:46:01 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2011-10-06 18:46:01 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2011-10-06 18:46:01 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2011-10-06 18:46:01 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2011-10-06 18:46:01 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-06 18:46:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
#include <time.h>
|
2011-10-06 18:46:01 +00:00
|
|
|
|
2022-12-12 21:29:25 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
|
2012-04-29 05:32:57 +00:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2013-10-29 20:35:29 +00:00
|
|
|
#include "screenshot.h"
|
2013-12-17 00:08:53 +00:00
|
|
|
#include "core.h"
|
2013-10-29 20:35:29 +00:00
|
|
|
#include "command.h"
|
2018-05-09 19:09:31 +00:00
|
|
|
#include "input/cmd.h"
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
#include "misc/dispatch.h"
|
2018-05-09 19:09:31 +00:00
|
|
|
#include "misc/node.h"
|
2018-05-09 20:38:21 +00:00
|
|
|
#include "misc/thread_tools.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/path.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/mp_image.h"
|
2017-01-12 12:02:19 +00:00
|
|
|
#include "video/mp_image_pool.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/out/vo.h"
|
|
|
|
#include "video/image_writer.h"
|
2019-09-14 20:06:00 +00:00
|
|
|
#include "video/sws_utils.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "sub/osd.h"
|
2011-10-06 18:46:01 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/csputils.h"
|
2011-10-06 18:46:01 +00:00
|
|
|
|
2012-10-20 21:32:45 +00:00
|
|
|
#define MODE_FULL_WINDOW 1
|
|
|
|
#define MODE_SUBTITLES 2
|
|
|
|
|
2011-10-06 18:46:01 +00:00
|
|
|
typedef struct screenshot_ctx {
|
2011-10-06 18:46:02 +00:00
|
|
|
struct MPContext *mpctx;
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
// Command to repeat in each-frame mode.
|
|
|
|
struct mp_cmd *each_frame;
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
int frameno;
|
player: make screenshot each-frame mode more accurate
Due to asynchronicity, we generally can't guarantee that a video frame
matches up with other events such as playback time change exactly (since
decoding, presentation, and property update all happen at different
times). This is a complaint in the referenced bug report, where
screenshot filenames in each-frame screenshot did not use the correct
timestamp, and instead was lagging behind by 1 frame.
But in this case, synchronicity was already pretty much forced with wait
calls. The only problem was that the playback time was updated at a
later time, which results in the observed 1 frame lag. Fix this by
moving the place where the screenshot is triggered in this mode.
Normal screenshots may still have the old problem. There is no effort
made to guarantee the timestamps absolutely line up, same as with the
OSD. (If you want a guarantee, you need to use a video filter, such as
libavfilter's drawtext. These will obviously use the proper timestamp,
instead of going through the somewhat asynchronous property etc. system
in the player frontend.)
Fixes: #7433
2020-02-07 12:32:07 +00:00
|
|
|
uint64_t last_frame_count;
|
2011-10-06 18:46:01 +00:00
|
|
|
} screenshot_ctx;
|
|
|
|
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
void screenshot_init(struct MPContext *mpctx)
|
2011-10-06 18:46:01 +00:00
|
|
|
{
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
mpctx->screenshot_ctx = talloc(mpctx, screenshot_ctx);
|
|
|
|
*mpctx->screenshot_ctx = (screenshot_ctx) {
|
|
|
|
.mpctx = mpctx,
|
|
|
|
.frameno = 1,
|
|
|
|
};
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
|
|
|
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
static char *stripext(void *talloc_ctx, const char *s)
|
2011-10-06 18:46:01 +00:00
|
|
|
{
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
const char *end = strrchr(s, '.');
|
|
|
|
if (!end)
|
|
|
|
end = s + strlen(s);
|
2012-10-28 19:05:50 +00:00
|
|
|
return talloc_asprintf(talloc_ctx, "%.*s", (int)(end - s), s);
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-07 16:00:19 +00:00
|
|
|
static bool write_screenshot(struct mp_cmd_ctx *cmd, struct mp_image *img,
|
2018-05-09 20:38:21 +00:00
|
|
|
const char *filename, struct image_writer_opts *opts)
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
{
|
2019-07-07 16:00:19 +00:00
|
|
|
struct MPContext *mpctx = cmd->mpctx;
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
struct image_writer_opts *gopts = mpctx->opts->screenshot_image_opts;
|
2018-05-09 20:38:21 +00:00
|
|
|
struct image_writer_opts opts_copy = opts ? *opts : *gopts;
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_V, "Starting screenshot: '%s'", filename);
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
mp_core_unlock(mpctx);
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
|
2019-10-31 14:44:09 +00:00
|
|
|
bool ok = img && write_image(img, &opts_copy, filename, mpctx->global,
|
|
|
|
mpctx->log);
|
2018-05-09 20:38:21 +00:00
|
|
|
|
|
|
|
mp_core_lock(mpctx);
|
|
|
|
|
|
|
|
if (ok) {
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_INFO, "Screenshot: '%s'", filename);
|
2018-05-09 20:38:21 +00:00
|
|
|
} else {
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_ERR, "Error writing screenshot!");
|
2018-05-09 20:38:21 +00:00
|
|
|
}
|
2018-05-10 13:00:27 +00:00
|
|
|
return ok;
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define ILLEGAL_FILENAME_CHARS "?\"/\\<>*|:"
|
|
|
|
#else
|
|
|
|
#define ILLEGAL_FILENAME_CHARS "/"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Replace all characters disallowed in filenames with '_' and return the newly
|
|
|
|
// allocated result string.
|
|
|
|
static char *sanitize_filename(void *talloc_ctx, const char *s)
|
|
|
|
{
|
|
|
|
char *res = talloc_strdup(talloc_ctx, s);
|
|
|
|
char *cur = res;
|
|
|
|
while (*cur) {
|
|
|
|
if (strchr(ILLEGAL_FILENAME_CHARS, *cur) || ((unsigned char)*cur) < 32)
|
|
|
|
*cur = '_';
|
|
|
|
cur++;
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
return res;
|
|
|
|
}
|
2011-10-06 18:46:01 +00:00
|
|
|
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
static void append_filename(char **s, const char *f)
|
|
|
|
{
|
|
|
|
char *append = sanitize_filename(NULL, f);
|
|
|
|
*s = talloc_strdup_append(*s, append);
|
|
|
|
talloc_free(append);
|
|
|
|
}
|
2011-10-06 18:46:01 +00:00
|
|
|
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
static char *create_fname(struct MPContext *mpctx, char *template,
|
|
|
|
const char *file_ext, int *sequence, int *frameno)
|
|
|
|
{
|
|
|
|
char *res = talloc_strdup(NULL, ""); //empty string, non-NULL context
|
|
|
|
|
|
|
|
time_t raw_time = time(NULL);
|
|
|
|
struct tm *local_time = localtime(&raw_time);
|
|
|
|
|
|
|
|
if (!template || *template == '\0')
|
2015-01-26 10:38:23 +00:00
|
|
|
return NULL;
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
char *next = strchr(template, '%');
|
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
res = talloc_strndup_append(res, template, next - template);
|
|
|
|
template = next + 1;
|
|
|
|
char fmt = *template++;
|
|
|
|
switch (fmt) {
|
|
|
|
case '#':
|
|
|
|
case '0':
|
|
|
|
case 'n': {
|
|
|
|
int digits = '4';
|
|
|
|
if (fmt == '#') {
|
|
|
|
if (!*sequence) {
|
|
|
|
*frameno = 1;
|
|
|
|
}
|
|
|
|
fmt = *template++;
|
|
|
|
}
|
|
|
|
if (fmt == '0') {
|
|
|
|
digits = *template++;
|
|
|
|
if (digits < '0' || digits > '9')
|
|
|
|
goto error_exit;
|
|
|
|
fmt = *template++;
|
|
|
|
}
|
|
|
|
if (fmt != 'n')
|
|
|
|
goto error_exit;
|
|
|
|
char fmtstr[] = {'%', '0', digits, 'd', '\0'};
|
|
|
|
res = talloc_asprintf_append(res, fmtstr, *frameno);
|
|
|
|
if (*frameno < 100000 - 1) {
|
|
|
|
(*frameno) += 1;
|
|
|
|
(*sequence) += 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'f':
|
|
|
|
case 'F': {
|
2015-09-02 02:41:16 +00:00
|
|
|
char *video_file = NULL;
|
|
|
|
if (mpctx->filename)
|
|
|
|
video_file = mp_basename(mpctx->filename);
|
|
|
|
|
|
|
|
if (!video_file)
|
|
|
|
video_file = "NO_FILE";
|
|
|
|
|
|
|
|
char *name = video_file;
|
|
|
|
if (fmt == 'F')
|
|
|
|
name = stripext(res, video_file);
|
|
|
|
append_filename(&res, name);
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-01-08 20:07:10 +00:00
|
|
|
case 'x':
|
|
|
|
case 'X': {
|
|
|
|
char *fallback = "";
|
|
|
|
if (fmt == 'X') {
|
|
|
|
if (template[0] != '{')
|
|
|
|
goto error_exit;
|
|
|
|
char *end = strchr(template, '}');
|
|
|
|
if (!end)
|
|
|
|
goto error_exit;
|
|
|
|
fallback = talloc_strndup(res, template + 1, end - template - 1);
|
|
|
|
template = end + 1;
|
|
|
|
}
|
|
|
|
if (!mpctx->filename || mp_is_url(bstr0(mpctx->filename))) {
|
|
|
|
res = talloc_strdup_append(res, fallback);
|
|
|
|
} else {
|
|
|
|
bstr dir = mp_dirname(mpctx->filename);
|
|
|
|
if (!bstr_equals0(dir, "."))
|
|
|
|
res = talloc_asprintf_append(res, "%.*s", BSTR_P(dir));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
case 'p':
|
2012-09-01 19:59:13 +00:00
|
|
|
case 'P': {
|
2014-06-29 17:27:46 +00:00
|
|
|
char *t = mp_format_time(get_playback_time(mpctx), fmt == 'P');
|
2012-09-01 19:59:13 +00:00
|
|
|
append_filename(&res, t);
|
|
|
|
talloc_free(t);
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
break;
|
2012-09-01 19:59:13 +00:00
|
|
|
}
|
2013-03-25 19:32:29 +00:00
|
|
|
case 'w': {
|
2013-09-15 17:07:35 +00:00
|
|
|
char tfmt = *template;
|
|
|
|
if (!tfmt)
|
2013-03-25 19:32:29 +00:00
|
|
|
goto error_exit;
|
|
|
|
template++;
|
2013-09-15 17:07:35 +00:00
|
|
|
char fmtstr[] = {'%', tfmt, '\0'};
|
2014-06-29 17:27:46 +00:00
|
|
|
char *s = mp_format_time_fmt(fmtstr, get_playback_time(mpctx));
|
2013-03-25 19:32:29 +00:00
|
|
|
if (!s)
|
|
|
|
goto error_exit;
|
|
|
|
append_filename(&res, s);
|
|
|
|
talloc_free(s);
|
|
|
|
break;
|
|
|
|
}
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
case 't': {
|
2013-07-22 22:45:23 +00:00
|
|
|
char tfmt = *template;
|
|
|
|
if (!tfmt)
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
goto error_exit;
|
|
|
|
template++;
|
2013-07-22 22:45:23 +00:00
|
|
|
char fmtstr[] = {'%', tfmt, '\0'};
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
char buffer[80];
|
|
|
|
if (strftime(buffer, sizeof(buffer), fmtstr, local_time) == 0)
|
|
|
|
buffer[0] = '\0';
|
|
|
|
append_filename(&res, buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '{': {
|
|
|
|
char *end = strchr(template, '}');
|
|
|
|
if (!end)
|
|
|
|
goto error_exit;
|
2012-07-28 21:47:42 +00:00
|
|
|
struct bstr prop = bstr_splice(bstr0(template), 0, end - template);
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
char *tmp = talloc_asprintf(NULL, "${%.*s}", BSTR_P(prop));
|
|
|
|
char *s = mp_property_expand_string(mpctx, tmp);
|
|
|
|
talloc_free(tmp);
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
if (s)
|
|
|
|
append_filename(&res, s);
|
|
|
|
talloc_free(s);
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
template = end + 1;
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '%':
|
|
|
|
res = talloc_strdup_append(res, "%");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res = talloc_strdup_append(res, template);
|
2013-12-14 18:50:00 +00:00
|
|
|
res = talloc_asprintf_append(res, ".%s", file_ext);
|
2013-12-21 19:45:19 +00:00
|
|
|
char *fname = mp_get_user_path(NULL, mpctx->global, res);
|
2013-12-14 18:50:00 +00:00
|
|
|
talloc_free(res);
|
|
|
|
return fname;
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
|
|
|
|
error_exit:
|
|
|
|
talloc_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-07 16:00:19 +00:00
|
|
|
static char *gen_fname(struct mp_cmd_ctx *cmd, const char *file_ext)
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
{
|
2019-07-07 16:00:19 +00:00
|
|
|
struct MPContext *mpctx = cmd->mpctx;
|
|
|
|
screenshot_ctx *ctx = mpctx->screenshot_ctx;
|
|
|
|
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
int sequence = 0;
|
|
|
|
for (;;) {
|
|
|
|
int prev_sequence = sequence;
|
|
|
|
char *fname = create_fname(ctx->mpctx,
|
2013-07-27 19:24:54 +00:00
|
|
|
ctx->mpctx->opts->screenshot_template,
|
2012-08-06 15:46:42 +00:00
|
|
|
file_ext,
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
&sequence,
|
|
|
|
&ctx->frameno);
|
|
|
|
|
|
|
|
if (!fname) {
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_ERR, "Invalid screenshot filename "
|
|
|
|
"template! Fix or remove the --screenshot-template "
|
|
|
|
"option.");
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-03 12:44:42 +00:00
|
|
|
char *dir = ctx->mpctx->opts->screenshot_directory;
|
2015-05-01 17:55:43 +00:00
|
|
|
if (dir && dir[0]) {
|
|
|
|
void *t = fname;
|
|
|
|
dir = mp_get_user_path(t, ctx->mpctx->global, dir);
|
2015-05-09 13:26:47 +00:00
|
|
|
fname = mp_path_join(NULL, dir, fname);
|
2015-05-02 14:38:38 +00:00
|
|
|
|
|
|
|
mp_mkdirp(dir);
|
2016-04-14 20:39:10 +00:00
|
|
|
|
|
|
|
talloc_free(t);
|
2015-05-01 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 23:28:27 +00:00
|
|
|
char *full_dir = bstrto0(fname, mp_dirname(fname));
|
|
|
|
if (!mp_path_exists(full_dir)) {
|
|
|
|
mp_mkdirp(full_dir);
|
|
|
|
}
|
|
|
|
|
2012-08-06 15:46:42 +00:00
|
|
|
if (!mp_path_exists(fname))
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
return fname;
|
|
|
|
|
|
|
|
if (sequence == prev_sequence) {
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_ERR, "Can't save screenshot, file '%s' "
|
|
|
|
"already exists!", fname);
|
2012-04-30 15:36:43 +00:00
|
|
|
talloc_free(fname);
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-29 17:54:01 +00:00
|
|
|
|
|
|
|
talloc_free(fname);
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
}
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-04 17:39:32 +00:00
|
|
|
static void add_subs(struct MPContext *mpctx, struct mp_image *image)
|
2011-10-06 18:46:01 +00:00
|
|
|
{
|
2015-12-19 19:04:31 +00:00
|
|
|
struct mp_osd_res res = osd_res_from_image_params(&image->params);
|
2014-06-15 18:46:57 +00:00
|
|
|
osd_draw_on_image(mpctx->osd, res, mpctx->video_pts,
|
2012-10-26 18:19:06 +00:00
|
|
|
OSD_DRAW_SUB_ONLY, image);
|
2012-10-20 21:32:45 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 19:18:36 +00:00
|
|
|
static struct mp_image *screenshot_get(struct MPContext *mpctx, int mode,
|
|
|
|
bool high_depth)
|
2011-10-06 18:46:01 +00:00
|
|
|
{
|
2013-07-08 18:34:26 +00:00
|
|
|
struct mp_image *image = NULL;
|
2022-12-12 21:29:25 +00:00
|
|
|
const struct image_writer_opts *imgopts = mpctx->opts->screenshot_image_opts;
|
2015-01-23 21:06:12 +00:00
|
|
|
if (mode == MODE_SUBTITLES && osd_get_render_subs_in_filter(mpctx->osd))
|
|
|
|
mode = 0;
|
2018-02-07 19:18:36 +00:00
|
|
|
bool need_add_subs = mode == MODE_SUBTITLES;
|
2012-10-20 21:32:45 +00:00
|
|
|
|
2023-03-04 20:26:37 +00:00
|
|
|
if (!mpctx->video_out || !mpctx->video_out->config_ok)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vo_wait_frame(mpctx->video_out); // important for each-frame mode
|
|
|
|
|
|
|
|
struct voctrl_screenshot ctrl = {
|
|
|
|
.scaled = mode == MODE_FULL_WINDOW,
|
|
|
|
.subs = mode != 0,
|
|
|
|
.osd = mode == MODE_FULL_WINDOW,
|
|
|
|
.high_bit_depth = high_depth && imgopts->high_bit_depth,
|
|
|
|
.native_csp = image_writer_flexible_csp(imgopts),
|
|
|
|
};
|
|
|
|
if (!mpctx->opts->screenshot_sw)
|
|
|
|
vo_control(mpctx->video_out, VOCTRL_SCREENSHOT, &ctrl);
|
|
|
|
image = ctrl.res;
|
|
|
|
if (image)
|
|
|
|
need_add_subs = false;
|
|
|
|
|
|
|
|
if (!image && mode != MODE_FULL_WINDOW)
|
|
|
|
image = vo_get_current_frame(mpctx->video_out);
|
|
|
|
if (!image) {
|
|
|
|
vo_control(mpctx->video_out, VOCTRL_SCREENSHOT_WIN, &image);
|
|
|
|
mode = MODE_FULL_WINDOW;
|
2015-01-23 21:06:12 +00:00
|
|
|
}
|
2023-03-04 20:26:37 +00:00
|
|
|
if (!image)
|
|
|
|
return NULL;
|
2012-11-04 17:39:32 +00:00
|
|
|
|
2023-03-04 20:26:37 +00:00
|
|
|
if (image->fmt.flags & MP_IMGFLAG_HWACCEL) {
|
2017-01-12 12:02:19 +00:00
|
|
|
struct mp_image *nimage = mp_image_hw_download(image, NULL);
|
2017-03-18 11:53:28 +00:00
|
|
|
talloc_free(image);
|
2023-03-04 20:26:37 +00:00
|
|
|
if (!nimage)
|
|
|
|
return NULL;
|
2017-03-18 11:53:28 +00:00
|
|
|
image = nimage;
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
2015-01-23 21:06:12 +00:00
|
|
|
|
2023-03-04 20:26:37 +00:00
|
|
|
if (need_add_subs)
|
2015-01-23 21:06:12 +00:00
|
|
|
add_subs(mpctx, image);
|
2022-12-12 21:17:19 +00:00
|
|
|
mp_image_params_guess_csp(&image->params);
|
2013-07-08 18:34:26 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2019-09-14 20:06:00 +00:00
|
|
|
struct mp_image *convert_image(struct mp_image *image, int destfmt,
|
2019-10-31 14:44:09 +00:00
|
|
|
struct mpv_global *global, struct mp_log *log)
|
2019-09-14 20:06:00 +00:00
|
|
|
{
|
|
|
|
int d_w, d_h;
|
|
|
|
mp_image_params_get_dsize(&image->params, &d_w, &d_h);
|
|
|
|
|
|
|
|
struct mp_image_params p = {
|
|
|
|
.imgfmt = destfmt,
|
|
|
|
.w = d_w,
|
|
|
|
.h = d_h,
|
|
|
|
.p_w = 1,
|
|
|
|
.p_h = 1,
|
|
|
|
};
|
|
|
|
mp_image_params_guess_csp(&p);
|
|
|
|
|
|
|
|
if (mp_image_params_equal(&p, &image->params))
|
|
|
|
return mp_image_new_ref(image);
|
|
|
|
|
|
|
|
struct mp_image *dst = mp_image_alloc(p.imgfmt, p.w, p.h);
|
|
|
|
if (!dst) {
|
|
|
|
mp_err(log, "Out of memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
mp_image_copy_attributes(dst, image);
|
|
|
|
|
|
|
|
dst->params = p;
|
|
|
|
|
2019-10-31 14:44:09 +00:00
|
|
|
struct mp_sws_context *sws = mp_sws_alloc(NULL);
|
|
|
|
sws->log = log;
|
|
|
|
if (global)
|
|
|
|
mp_sws_enable_cmdline_opts(sws, global);
|
|
|
|
bool ok = mp_sws_scale(sws, dst, image) >= 0;
|
|
|
|
talloc_free(sws);
|
|
|
|
|
|
|
|
if (!ok) {
|
2019-09-14 20:06:00 +00:00
|
|
|
mp_err(log, "Error when converting image.\n");
|
|
|
|
talloc_free(dst);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
// mode is the same as in screenshot_get()
|
2018-05-09 19:09:31 +00:00
|
|
|
static struct mp_image *screenshot_get_rgb(struct MPContext *mpctx, int mode)
|
2015-04-20 21:11:03 +00:00
|
|
|
{
|
2018-02-07 19:18:36 +00:00
|
|
|
struct mp_image *mpi = screenshot_get(mpctx, mode, false);
|
2015-04-20 21:11:03 +00:00
|
|
|
if (!mpi)
|
|
|
|
return NULL;
|
2019-10-31 14:44:09 +00:00
|
|
|
struct mp_image *res = convert_image(mpi, IMGFMT_BGR0, mpctx->global,
|
|
|
|
mpctx->log);
|
2015-04-20 21:11:03 +00:00
|
|
|
talloc_free(mpi);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
void cmd_screenshot_to_file(void *p)
|
2013-07-08 18:34:26 +00:00
|
|
|
{
|
2018-05-09 20:38:21 +00:00
|
|
|
struct mp_cmd_ctx *cmd = p;
|
|
|
|
struct MPContext *mpctx = cmd->mpctx;
|
|
|
|
const char *filename = cmd->args[0].v.s;
|
|
|
|
int mode = cmd->args[1].v.i;
|
2013-07-27 19:24:54 +00:00
|
|
|
struct image_writer_opts opts = *mpctx->opts->screenshot_image_opts;
|
2013-07-08 18:34:26 +00:00
|
|
|
|
|
|
|
char *ext = mp_splitext(filename, NULL);
|
2017-03-18 14:03:05 +00:00
|
|
|
int format = image_writer_format_from_ext(ext);
|
|
|
|
if (format)
|
|
|
|
opts.format = format;
|
2018-02-07 19:18:36 +00:00
|
|
|
bool high_depth = image_writer_high_depth(&opts);
|
|
|
|
struct mp_image *image = screenshot_get(mpctx, mode, high_depth);
|
2013-07-08 18:34:26 +00:00
|
|
|
if (!image) {
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_ERR, "Taking screenshot failed.");
|
2018-05-10 13:00:27 +00:00
|
|
|
cmd->success = false;
|
2018-05-09 20:38:21 +00:00
|
|
|
return;
|
2013-07-08 18:34:26 +00:00
|
|
|
}
|
2019-07-07 16:00:19 +00:00
|
|
|
cmd->success = write_screenshot(cmd, image, filename, &opts);
|
2013-07-08 18:34:26 +00:00
|
|
|
talloc_free(image);
|
|
|
|
}
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
void cmd_screenshot(void *p)
|
2013-07-08 18:34:26 +00:00
|
|
|
{
|
2018-05-09 20:38:21 +00:00
|
|
|
struct mp_cmd_ctx *cmd = p;
|
|
|
|
struct MPContext *mpctx = cmd->mpctx;
|
2023-03-23 15:49:38 +00:00
|
|
|
struct mpv_node *res = &cmd->result;
|
2018-05-09 20:38:21 +00:00
|
|
|
int mode = cmd->args[0].v.i & 3;
|
|
|
|
bool each_frame_toggle = (cmd->args[0].v.i | cmd->args[1].v.i) & 8;
|
|
|
|
bool each_frame_mode = cmd->args[0].v.i & 16;
|
|
|
|
|
2013-07-08 18:34:26 +00:00
|
|
|
screenshot_ctx *ctx = mpctx->screenshot_ctx;
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
if (mode == MODE_SUBTITLES && osd_get_render_subs_in_filter(mpctx->osd))
|
2013-07-08 18:34:26 +00:00
|
|
|
mode = 0;
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
if (!each_frame_mode) {
|
|
|
|
if (each_frame_toggle) {
|
|
|
|
if (ctx->each_frame) {
|
|
|
|
TA_FREEP(&ctx->each_frame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->each_frame = talloc_steal(ctx, mp_cmd_clone(cmd->cmd));
|
|
|
|
ctx->each_frame->args[0].v.i |= 16;
|
|
|
|
} else {
|
|
|
|
TA_FREEP(&ctx->each_frame);
|
|
|
|
}
|
2013-07-08 18:34:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 13:00:27 +00:00
|
|
|
cmd->success = false;
|
|
|
|
|
2018-02-07 19:18:36 +00:00
|
|
|
struct image_writer_opts *opts = mpctx->opts->screenshot_image_opts;
|
|
|
|
bool high_depth = image_writer_high_depth(opts);
|
|
|
|
|
|
|
|
struct mp_image *image = screenshot_get(mpctx, mode, high_depth);
|
2013-07-08 18:34:26 +00:00
|
|
|
|
|
|
|
if (image) {
|
2019-07-07 16:00:19 +00:00
|
|
|
char *filename = gen_fname(cmd, image_writer_file_ext(opts));
|
2023-03-23 15:49:38 +00:00
|
|
|
if (filename) {
|
2019-07-07 16:00:19 +00:00
|
|
|
cmd->success = write_screenshot(cmd, image, filename, NULL);
|
2023-03-23 15:49:38 +00:00
|
|
|
if (cmd->success) {
|
|
|
|
node_init(res, MPV_FORMAT_NODE_MAP, NULL);
|
|
|
|
node_map_add_string(res, "filename", filename);
|
|
|
|
}
|
|
|
|
}
|
player: make screenshot commands honor the async flag
And also change input.conf to make all screenshots async. (Except the
every-frame mode, which always uses synchronous mode and ignores the
flag.) By default, the "screenshot" command is still asynchronous,
because scripts etc. might depend on this behavior.
This is only partially async. The code for determining the filename is
still always run synchronously. Only encoding the screenshot and writing
it to disk is asynchronous. We explicitly document the exact behavior as
undefined, so it can be changed any time.
Some of this is a bit messy, because I wanted to avoid duplicating the
message display code between sync and async mode. In async mode, this is
called from a worker thread, which is not safe because showing a message
accesses the thread-unsafe OSD code. So the core has to be locked during
this, which implies accessing the core and all that. So the code has
weird locking calls, and we need to do core destruction in a more
"controlled" manner (thus the outstanding_async field).
(What I'd really want would be the OSD simply showing log messages
instead.)
This is pretty untested, so expect bugs.
Fixes #4250.
2017-04-01 18:45:20 +00:00
|
|
|
talloc_free(filename);
|
2013-07-08 18:34:26 +00:00
|
|
|
} else {
|
2019-07-07 16:00:19 +00:00
|
|
|
mp_cmd_msg(cmd, MSGL_ERR, "Taking screenshot failed.");
|
2013-07-08 18:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
talloc_free(image);
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 19:09:31 +00:00
|
|
|
void cmd_screenshot_raw(void *p)
|
|
|
|
{
|
|
|
|
struct mp_cmd_ctx *cmd = p;
|
|
|
|
struct MPContext *mpctx = cmd->mpctx;
|
|
|
|
struct mpv_node *res = &cmd->result;
|
|
|
|
|
|
|
|
struct mp_image *img = screenshot_get_rgb(mpctx, cmd->args[0].v.i);
|
|
|
|
if (!img) {
|
|
|
|
cmd->success = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node_init(res, MPV_FORMAT_NODE_MAP, NULL);
|
|
|
|
node_map_add_int64(res, "w", img->w);
|
|
|
|
node_map_add_int64(res, "h", img->h);
|
|
|
|
node_map_add_int64(res, "stride", img->stride[0]);
|
|
|
|
node_map_add_string(res, "format", "bgr0");
|
|
|
|
struct mpv_byte_array *ba =
|
|
|
|
node_map_add(res, "data", MPV_FORMAT_BYTE_ARRAY)->u.ba;
|
|
|
|
*ba = (struct mpv_byte_array){
|
|
|
|
.data = img->planes[0],
|
|
|
|
.size = img->stride[0] * img->h,
|
|
|
|
};
|
|
|
|
talloc_steal(ba, img);
|
|
|
|
}
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
static void screenshot_fin(struct mp_cmd_ctx *cmd)
|
|
|
|
{
|
|
|
|
void **a = cmd->on_completion_priv;
|
|
|
|
struct MPContext *mpctx = a[0];
|
|
|
|
struct mp_waiter *waiter = a[1];
|
|
|
|
|
|
|
|
mp_waiter_wakeup(waiter, 0);
|
|
|
|
mp_wakeup_core(mpctx);
|
|
|
|
}
|
|
|
|
|
player: make screenshot each-frame mode more accurate
Due to asynchronicity, we generally can't guarantee that a video frame
matches up with other events such as playback time change exactly (since
decoding, presentation, and property update all happen at different
times). This is a complaint in the referenced bug report, where
screenshot filenames in each-frame screenshot did not use the correct
timestamp, and instead was lagging behind by 1 frame.
But in this case, synchronicity was already pretty much forced with wait
calls. The only problem was that the playback time was updated at a
later time, which results in the observed 1 frame lag. Fix this by
moving the place where the screenshot is triggered in this mode.
Normal screenshots may still have the old problem. There is no effort
made to guarantee the timestamps absolutely line up, same as with the
OSD. (If you want a guarantee, you need to use a video filter, such as
libavfilter's drawtext. These will obviously use the proper timestamp,
instead of going through the somewhat asynchronous property etc. system
in the player frontend.)
Fixes: #7433
2020-02-07 12:32:07 +00:00
|
|
|
void handle_each_frame_screenshot(struct MPContext *mpctx)
|
2011-10-06 18:46:01 +00:00
|
|
|
{
|
screenshot: make screenshot filenames configurable
This adds the --screenshot-template option, which specifies a template
for the filename used for a screenshot. The '%' character is parsed as
format specifier. These format specifiers insert metadata into the
filename. For example, '%f' is replaced with the filename of the
currently played file.
The following format specifiers are available:
%n Insert sequence number (padded with 4 zeros), e.g. "0002".
%0Nn Like %n, but pad to N zeros (N = 0 to 9).
%n behaves like %04n.
%#n Like %n, but reset the sequence counter on every screenshot.
(Useful if other parts in the template make the resulting
filename already mostly unique.)
%#0Nn Use %0Nn and %#n at the same time.
%f Insert filename of the currently played video.
%F Like %f, but with stripped file extension ("." and rest).
%p Insert current playback time, in HH:MM:SS format.
%P Like %p, but adds milliseconds: HH:MM:SS.mmmm
%tX Insert the current local date/time, using the date format X.
X is a single letter and is passed to strftime() as "%X".
E.g. "%td" inserts the number of the current day.
%{prop} Insert the value of the slave property 'prop'.
E.g. %{filename} is the same as %f. If the property doesn't
exist or is not available, nothing is inserted, unless a
fallback is specified as in %{prop:fallback text}.
%% Insert the character '%'.
The strings inserted by format specifiers will be checked for
characters not allowed in filenames (including '/' and '\'), and
replaced with the placeholder '_'. (This doesn't happen for text that
was passed with the --screenshot-template option, and allows specifying
a screenshot target directory by prefixing the template with a relative
or absolute path.)
2012-02-29 02:46:25 +00:00
|
|
|
screenshot_ctx *ctx = mpctx->screenshot_ctx;
|
2011-10-06 18:46:01 +00:00
|
|
|
|
|
|
|
if (!ctx->each_frame)
|
|
|
|
return;
|
|
|
|
|
player: make screenshot each-frame mode more accurate
Due to asynchronicity, we generally can't guarantee that a video frame
matches up with other events such as playback time change exactly (since
decoding, presentation, and property update all happen at different
times). This is a complaint in the referenced bug report, where
screenshot filenames in each-frame screenshot did not use the correct
timestamp, and instead was lagging behind by 1 frame.
But in this case, synchronicity was already pretty much forced with wait
calls. The only problem was that the playback time was updated at a
later time, which results in the observed 1 frame lag. Fix this by
moving the place where the screenshot is triggered in this mode.
Normal screenshots may still have the old problem. There is no effort
made to guarantee the timestamps absolutely line up, same as with the
OSD. (If you want a guarantee, you need to use a video filter, such as
libavfilter's drawtext. These will obviously use the proper timestamp,
instead of going through the somewhat asynchronous property etc. system
in the player frontend.)
Fixes: #7433
2020-02-07 12:32:07 +00:00
|
|
|
if (ctx->last_frame_count == mpctx->shown_vframes)
|
|
|
|
return;
|
|
|
|
ctx->last_frame_count = mpctx->shown_vframes;
|
|
|
|
|
2018-05-09 20:38:21 +00:00
|
|
|
struct mp_waiter wait = MP_WAITER_INITIALIZER;
|
|
|
|
void *a[] = {mpctx, &wait};
|
2018-05-12 16:46:37 +00:00
|
|
|
run_command(mpctx, mp_cmd_clone(ctx->each_frame), NULL, screenshot_fin, a);
|
2018-05-09 20:38:21 +00:00
|
|
|
|
2020-02-07 12:42:22 +00:00
|
|
|
// Block (in a reentrant way) until the screenshot was written. Otherwise,
|
2018-05-09 20:38:21 +00:00
|
|
|
// we could pile up screenshot requests forever.
|
|
|
|
while (!mp_waiter_poll(&wait))
|
|
|
|
mp_idle(mpctx);
|
|
|
|
|
|
|
|
mp_waiter_wait(&wait);
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|