2011-10-06 18:46:01 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mplayer2.
|
|
|
|
*
|
|
|
|
* mplayer2 is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mplayer2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mplayer2; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
#include "config.h"
|
2011-10-06 18:46:02 +00:00
|
|
|
|
2012-04-29 05:32:57 +00:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2011-10-06 18:46:01 +00:00
|
|
|
#include "talloc.h"
|
|
|
|
#include "screenshot.h"
|
|
|
|
#include "mp_core.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 "m_property.h"
|
|
|
|
#include "bstr.h"
|
2011-10-06 18:46:01 +00:00
|
|
|
#include "mp_msg.h"
|
2012-02-03 07:05:11 +00:00
|
|
|
#include "path.h"
|
2011-10-06 18:46:01 +00:00
|
|
|
#include "libmpcodecs/mp_image.h"
|
|
|
|
#include "libmpcodecs/dec_video.h"
|
|
|
|
#include "libmpcodecs/vf.h"
|
|
|
|
#include "libvo/video_out.h"
|
2012-08-06 15:46:42 +00:00
|
|
|
#include "image_writer.h"
|
2011-10-06 18:46:01 +00:00
|
|
|
|
|
|
|
#include "libvo/csputils.h"
|
|
|
|
|
|
|
|
typedef struct screenshot_ctx {
|
2011-10-06 18:46:02 +00:00
|
|
|
struct MPContext *mpctx;
|
|
|
|
|
2011-10-06 18:46:01 +00:00
|
|
|
int full_window;
|
2011-10-06 18:46:01 +00:00
|
|
|
int each_frame;
|
|
|
|
int using_vf_screenshot;
|
|
|
|
|
|
|
|
int frameno;
|
|
|
|
} 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);
|
|
|
|
return talloc_asprintf(talloc_ctx, "%.*s", end - s, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *do_format_property(struct MPContext *mpctx, struct bstr s) {
|
|
|
|
struct bstr prop_name = s;
|
|
|
|
int fallbackpos = bstrchr(s, ':');
|
|
|
|
if (fallbackpos >= 0)
|
|
|
|
prop_name = bstr_splice(prop_name, 0, fallbackpos);
|
|
|
|
char *pn = bstrdup0(NULL, prop_name);
|
|
|
|
char *res = mp_property_print(pn, mpctx);
|
|
|
|
talloc_free(pn);
|
|
|
|
if (!res && fallbackpos >= 0)
|
|
|
|
res = bstrdup0(NULL, bstr_cut(s, fallbackpos + 1));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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')
|
|
|
|
template = "shot%n";
|
|
|
|
|
|
|
|
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': {
|
2012-09-06 03:29:38 +00:00
|
|
|
char *video_file = mp_basename(mpctx->filename);
|
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 (video_file) {
|
|
|
|
char *name = video_file;
|
|
|
|
if (fmt == 'F')
|
|
|
|
name = stripext(res, video_file);
|
|
|
|
append_filename(&res, name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'p':
|
2012-09-01 19:59:13 +00:00
|
|
|
case 'P': {
|
|
|
|
char *t = mp_format_time(get_current_time(mpctx), fmt == 'P');
|
|
|
|
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
|
|
|
}
|
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': {
|
|
|
|
char fmt = *template;
|
|
|
|
if (!fmt)
|
|
|
|
goto error_exit;
|
|
|
|
template++;
|
|
|
|
char fmtstr[] = {'%', fmt, '\0'};
|
|
|
|
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);
|
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
|
|
|
template = end + 1;
|
|
|
|
char *s = do_format_property(mpctx, prop);
|
|
|
|
if (s)
|
|
|
|
append_filename(&res, s);
|
|
|
|
talloc_free(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '%':
|
|
|
|
res = talloc_strdup_append(res, "%");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res = talloc_strdup_append(res, template);
|
|
|
|
return talloc_asprintf_append(res, ".%s", file_ext);
|
|
|
|
|
|
|
|
error_exit:
|
|
|
|
talloc_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-06 15:46:42 +00:00
|
|
|
static char *gen_fname(screenshot_ctx *ctx, 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
|
|
|
{
|
|
|
|
int sequence = 0;
|
|
|
|
for (;;) {
|
|
|
|
int prev_sequence = sequence;
|
|
|
|
char *fname = create_fname(ctx->mpctx,
|
|
|
|
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) {
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Invalid screenshot filename "
|
|
|
|
"template! Fix or remove the --screenshot-template option."
|
|
|
|
"\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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) {
|
2012-04-29 17:54:01 +00:00
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Can't save screenshot, file '%s' "
|
|
|
|
"already exists!\n", 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
|
|
|
}
|
|
|
|
|
|
|
|
void screenshot_save(struct MPContext *mpctx, struct mp_image *image)
|
|
|
|
{
|
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
|
|
|
|
2012-08-06 15:46:42 +00:00
|
|
|
struct mp_csp_details colorspace;
|
|
|
|
get_detected_video_colorspace(mpctx->sh_video, &colorspace);
|
|
|
|
|
2012-08-06 15:48:30 +00:00
|
|
|
struct image_writer_opts *opts = mpctx->opts.screenshot_image_opts;
|
2012-08-06 15:46:42 +00:00
|
|
|
|
2012-08-06 15:48:30 +00:00
|
|
|
char *filename = gen_fname(ctx, image_writer_file_ext(opts));
|
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 (filename) {
|
2012-08-06 15:46:42 +00:00
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_INFO, "*** screenshot '%s' ***\n", filename);
|
2012-08-06 15:48:30 +00:00
|
|
|
if (!write_image(image, &colorspace, opts, filename))
|
2012-08-06 15:46:42 +00:00
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_ERR, "\nError writing screenshot!\n");
|
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
|
|
|
talloc_free(filename);
|
|
|
|
}
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vf_screenshot_callback(void *pctx, struct mp_image *image)
|
|
|
|
{
|
|
|
|
struct MPContext *mpctx = (struct MPContext *)pctx;
|
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
|
|
|
screenshot_save(mpctx, image);
|
|
|
|
if (ctx->each_frame)
|
2011-10-06 18:46:01 +00:00
|
|
|
screenshot_request(mpctx, 0, ctx->full_window);
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 02:50:08 +00:00
|
|
|
static bool force_vf(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
if (mpctx->sh_video) {
|
|
|
|
struct vf_instance *vf = mpctx->sh_video->vfilter;
|
|
|
|
while (vf) {
|
|
|
|
if (strcmp(vf->info->name, "screenshot_force") == 0)
|
|
|
|
return true;
|
|
|
|
vf = vf->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-06 18:46:01 +00:00
|
|
|
void screenshot_request(struct MPContext *mpctx, bool each_frame,
|
|
|
|
bool full_window)
|
2011-10-06 18:46:01 +00:00
|
|
|
{
|
|
|
|
if (mpctx->video_out && mpctx->video_out->config_ok) {
|
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
|
|
|
|
|
|
|
ctx->using_vf_screenshot = 0;
|
|
|
|
|
|
|
|
if (each_frame) {
|
|
|
|
ctx->each_frame = !ctx->each_frame;
|
2011-10-06 18:46:01 +00:00
|
|
|
ctx->full_window = full_window;
|
2011-10-06 18:46:01 +00:00
|
|
|
if (!ctx->each_frame)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-06 18:46:01 +00:00
|
|
|
struct voctrl_screenshot_args args = { .full_window = full_window };
|
2012-01-17 02:50:08 +00:00
|
|
|
if (!force_vf(mpctx)
|
|
|
|
&& vo_control(mpctx->video_out, VOCTRL_SCREENSHOT, &args) == true)
|
|
|
|
{
|
2011-10-06 18:46:01 +00:00
|
|
|
screenshot_save(mpctx, args.out_image);
|
|
|
|
free_mp_image(args.out_image);
|
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_INFO, "No VO support for taking"
|
|
|
|
" screenshots, trying VFCTRL_SCREENSHOT!\n");
|
|
|
|
ctx->using_vf_screenshot = 1;
|
|
|
|
struct vf_ctrl_screenshot cmd = {
|
|
|
|
.image_callback = vf_screenshot_callback,
|
|
|
|
.image_callback_ctx = mpctx,
|
|
|
|
};
|
|
|
|
struct vf_instance *vfilter = mpctx->sh_video->vfilter;
|
|
|
|
if (vfilter->control(vfilter, VFCTRL_SCREENSHOT, &cmd) !=
|
|
|
|
CONTROL_OK)
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_INFO,
|
|
|
|
"...failed (need --vf=screenshot?)\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void screenshot_flip(struct MPContext *mpctx)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
// screenshot_flip is called when the VO presents a new frame. vf_screenshot
|
|
|
|
// can behave completely different (consider filters inserted between
|
|
|
|
// vf_screenshot and vf_vo, that add or remove frames), so handle this case
|
|
|
|
// somewhere else.
|
|
|
|
if (ctx->using_vf_screenshot)
|
|
|
|
return;
|
|
|
|
|
2011-10-06 18:46:01 +00:00
|
|
|
screenshot_request(mpctx, 0, ctx->full_window);
|
2011-10-06 18:46:01 +00:00
|
|
|
}
|