Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/screenshot-template-time.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
change `%tX` format specifier of `--screenshot-template` option to only accept C11 strftime specifiers or `%s` specifier
6 changes: 6 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5031,6 +5031,12 @@ Screenshot
the result of passing "%X" to ``strftime``. For example, ``%tm`` will
insert the number of the current month as number. You have to use
multiple ``%tX`` specifiers to build a full date/time string.

.. note::

Since mpv 0.42.0, this only supports the ``strftime`` format
specifiers specified in C11 standard, or the ``%s`` extension for
UNIX timestamp. Other format specifiers are unsupported.
``%{prop[:fallback text]}``
Insert the value of the input property 'prop'. E.g. ``%{filename}`` is
the same as ``%f``. If the property does not exist or is not available,
Expand Down
15 changes: 11 additions & 4 deletions player/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,20 @@ static char *create_fname(struct MPContext *mpctx, char *template,
}
case 't': {
char tfmt = *template;
if (!tfmt)
// Translate common extensions to the closest alternative.
size_t i = strcspn("sklPaAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%", (char[]){tfmt, '\0'});
tfmt = "sHIpaAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%"[i];
if (!tfmt || !local_time)
goto error_exit;
template++;
char fmtstr[] = {'%', tfmt, '\0'};
char buffer[80];
if (strftime(buffer, sizeof(buffer), fmtstr, local_time) == 0)
buffer[0] = '\0';
if (tfmt == 's') {
snprintf(buffer, sizeof(buffer), "%"PRId64, (int64_t)raw_time);
} else {
char fmtstr[] = {'%', tfmt, '\0'};
if (strftime(buffer, sizeof(buffer), fmtstr, local_time) == 0)
buffer[0] = '\0';
}
append_filename(&res, buffer);
break;
}
Expand Down
Loading