Commit Graph

3802 Commits

Author SHA1 Message Date
nanahi 86e8cae9ca stats.lua: add nonscalable prefix to cmd_prefixes 2024-10-14 01:55:49 +02:00
nanahi 72a705c598 console.lua: add nonscalable prefix to command_prefixes 2024-10-14 01:55:49 +02:00
Guido Cella e34f6569ee stats.lua: rename a variable 2024-10-12 21:24:41 +02:00
Guido Cella ba3b4eda64 console.lua: use ${term-clip-cc} to clip lines
Instead of considering every non-ASCII character 2-cell wide, use this
newly introduced property to let msg.c clip the select menu using all
available with.
2024-10-11 15:31:17 +02:00
Kacper Michajłow bf025cd289 msg: allow to truncate the message to terminal width 2024-10-11 15:16:33 +02:00
Crend King c8860fd816 ytdl_hook.lua: always specify --write-srt
Currently by default mpv sets --all-subs when calling yt-dlp for JSON
info. --all-subs is an option that simply expands to --sub-langs all
--write-subs. --write-subs is special that without it yt-dlp will no
longer extract any subtitle info.

mpv's yt-dlp hook has a logic that if user specify any sub-langs in
--ytdl-raw-options, it no longer uses --all-subs. Unfortunately, this
means unaware users will not get any subtitle any more until they study
the mpv internal code and add their own --write-subs.

This PR always specifies --write-srt, an alias of --write-subs, in the
hook, so users don't have to. The alias is used to maintain
compatibility with youtube-dl.

Fixes issue #14818
2024-10-10 18:28:41 +02:00
Dudemanguy 901b9bc888 player/sub: ensure subtitles are updated for images with no audio
The video_pts condition here would bail out on still images with no
audio since their pts is always MP_NOPTS_VALUE. This is not exactly
great because the subtitles may need to be updated so just let these
files also go through the subtitle redraw logic below.
2024-10-10 13:17:47 +00:00
Guido Cella 6ed3781a3d ytdl_hook.lua: add include script-opt of URLs to try with ytdl first
By the default mpv tries opening URLs with ffmpeg first, and users who
don't configure try_ytdl_first get a slower startup for youtube URLs, on
top of yt-dlp already being slow.

Fix this by adding a script-opt of URL pattern to try with ytdl first.
Youtube and twitch are included by default.

Compared to the alternative of trying ytdl first by default and
excluding URLs with a media extension, this only works for the sites
explicitly included in the new option's value, but doesn't have false
positives on media URLs without an extension.
2024-10-09 01:08:31 +02:00
Guido Cella 92403a068c ytdl_hook.lua: lower case URLs for exclude matching 2024-10-09 01:08:31 +02:00
Mohammad AlSaleh 28a4e19a67 command: avoid division by zero in av_timecode_make_string()
`av_timecode_make_string()` divides by fps unconditionally. And
 relying on container_fps always carrying a meaningful value was
 misguided. So we now check that fps is non-zero before calling that
 function.

 Issue encountered with a couple of old FLV files triggering a segfault.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-10-09 00:36:35 +02:00
Guido Cella 8bf5548589 console.lua: allow clicking selectable items
This adds click support for the select menu. Scrolling with the wheel
already worked.

If a custom OSC binds a button to a select.lua script-binding, this lets
users keep using the mouse to select an item.

While the OSC and the select menu are open at the same time, you can no
longer click the OSC's buttons. By using mp.add_key_binding instead of
add_forced_key_binding you could click both, but the console's binding
would be shadowed by MBTN_LEFT bindings in input.conf.
2024-10-08 20:37:56 +02:00
Guido Cella 493cab7efc stats.lua: allow keybindings to toggle the display of a specific page
This lets you define bindings like h script-binding
stats/display-page-4-toggle. Requested in #14966.
2024-10-04 21:13:29 +03:00
Guido Cella be814e3753 stats.lua: scroll keybindings while filtering them
console.lua binds up and down to navigate its history. Add a private
flag to mp.input.get to instruct console.lua not to bind up and down, so
you can use them to scroll the keybindings page while filtering
keybindings.

If it is requested, this can be replaced with an argument to input.get
to not bind arbitrary keys.

Fixes #14966.
2024-10-04 21:13:29 +03:00
Guido Cella b3f8464fa9 input.lua,defaults.js: don't hardcode mp.input arguments
Pass everything in the tables passed by mp.input callers to console.lua
so new flags can be added without modifying these clients.

In Lua, callbacks have to be excluded from the argument tables to not
make utils.format_json() error, while with JSON.stringify they are
automatically omitted.
2024-10-04 21:13:29 +03:00
Guido Cella dcd681ecdd stats.lua: filter keybindings by comment
Requested in #14966.
2024-10-04 21:13:29 +03:00
Kacper Michajłow 7202406fe8 various: remove global.h inclusion where not needed 2024-10-01 12:23:44 +02:00
nanahi 151fa74806 player/external_files: fix null deref when cover-art-whitelist is empty
This can happen when using --cover-art-whitelist-clr.

Fixes: d384a6b793
2024-09-29 22:56:40 +02:00
Andreas Klauer c365e2f7b1 misc/random: seed using libavutil/random_seed
When starting multiple processes of `mpv --shuffle` in parallel,
sometimes the random seed happens to be identical, so files are
played in the same random order.

mp_rand_seed(0) now uses a random seed provided by libavutil,
and only falls back to time in case of failure.
2024-09-28 14:11:56 +02:00
Guido Cella 69ced646f8 lua: remove unused #define mp_lua_len
This is unused since 548ef07864 and 7f91e2684e.
2024-09-26 16:45:08 +02:00
Dudemanguy b52a67dde2 meson: bump required version to 1.3.0
Newer meson versions added support for features that mpv has been using
for a long time. Annoying fallbacks were left in place to not break old
versions but ideally everyone should be using the newer build features.
Both the latest ubuntu LTS and debian stable (in backports) have 1.5.0
in their repos, so go ahead and bump the version so we can drop some old
code and let developers use newer meson features if applicable.
2024-09-24 22:16:59 +00:00
Kacper Michajłow 1c55d600ab stats.lua: add timecode display 2024-09-24 19:47:42 +02:00
llyyr d33bcc51a7 command: add video-frame-info/{gop,smpte,estimated-smpte}-timecode
Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2024-09-24 19:47:42 +02:00
Kacper Michajłow 2a1485772b console.lua: clear terminal msg after changing to OSD display 2024-09-24 19:21:00 +02:00
llyyr e538c7f413 player/main: guard smtc.h include 2024-09-23 22:13:51 +02:00
Dudemanguy 2bd1e78701 build: ensure HAVE_WIN32_SMTC is always defined
It makes sense to only descend into the subdirectory meson build file on
windows, but we should always make sure HAVE_WIN32_SMTC is 0 for other
platforms. Otherwise, it gets unneccesarily awkward to work with.
2024-09-23 22:13:51 +02:00
Guido Cella 68ea9fecda console.lua: fix the height calculation with --video-osd=no 2024-09-22 17:31:54 +02:00
Kacper Michajłow 71f2220991 meson: use relative file paths for file2string
This fixes "Generated from" comments to not include local source path in
generated files.
2024-09-21 23:39:10 +02:00
Maxim Biro ff47926d6a ytdl_hook: make path and json available to other scripts
It's useful for user scripts to be able to use the same ytdl binary that
ytdl_hook uses without having to replicate ytdl_hook's process of
searching for the ytdl binary.

Some user scripts might also find it useful to be able to access ytdl's
json output that the ytdl_hook already receives, sparing user scripts
from having to make a duplicate ytdl binary invocation to get the json
output.

Providing just the json output is not enough though, as ytdl doesn't communicate
errors though it -- if an error occurs, ytdl provides no json output and instead
prints to stderr. So without stderr, there is no way for user scripts to figure
out why ytdl has failed: no such username / video id, the channel is not live
yet, etc. Because of that, the entire result of the subprocess call is provided
to the user scripts, containing stdout (json), stderr, ytdl's exit code, etc.
2024-09-21 17:53:01 +02:00
Guido Cella e3eeaec813 select.lua: don't use add_forced_key_binding
There's no advantage in using the forced version here. It is a leftover
from when this was an external script and forced was necessary to bind
key sequences reliably until 3f83671f20.
2024-09-19 13:57:39 +00:00
llyyr 140196f297 ytdl_hook: fix typo (chapters -> chapter)
Fixes: ec966fb866
2024-09-19 13:55:58 +00:00
Guido Cella 030c283ef5 console.lua: respect --video-osd=no 2024-09-15 18:27:24 +02:00
Guido Cella 8592206c75 console.lua: truncate more characters with --msg-module and --msg-time
Fix the terminal width calculation for the select menu with these
options.
2024-09-15 18:27:24 +02:00
Guido Cella b98d4fde0d console.lua: fix highlighting the selected item with --msg-module
With --msg-module the select menu also highlights the "statusline" on
the next line. Fix this by resetting the color before \n instead of
after it.

This requires changing all log code to not preemptively add a newline,
which is actually simpler, though we have to modify the messages
received with log-message which already contain a newline.
2024-09-15 18:27:24 +02:00
nanahi 42b40d03f1 player/main: revert msg uninit order changes
msg must be the last module to uninit since pretty much
everything else uses logging.

This reverts commit f92d5da89c.
This reverts commit c1282d4d43.
2024-09-15 17:03:33 +02:00
Kacper Michajłow a6e13f41eb console.lua: sync colors after msg.c change
Keep ASS pallete the same, as it doesn't print trace messages anyway.
Remove only bold and keep debug gray.
2024-09-14 17:11:07 +02:00
Guido Cella 7362f72fdf console.lua: fix completing empty --dscale and --cscale
These options accept an empty value within their choices. If the user
didn't add manually input a quote before completing them, add quotes
automatically so that the blank value can actually be used.
2024-09-14 17:06:07 +02:00
llyyr ec966fb866 ytdl_hook: add some more yt-dlp tags
These might be useful
2024-09-14 14:07:54 +02:00
Oneric 5357d18fe6 sub: add ass-video-aspect-override option
It is unclear whether there actually is any usecase for this option
which isn't better served by sub-ass-use-video-data and/or LayoutRes
overrides, but prior to the introduction of sub-ass-use-video-data
it was possible to pass along storage resolution while faking an
aspect ratio of 1:1.
sub-ass-video-aspect-override=1 combined with sub-ass-use-video-data=all
now makes this possible again.

The uper limit of a 10:1 aspect matches
the general video-aspect-override option.
2024-09-13 23:24:08 +02:00
Oneric 207b1a2c91 sub: merge vsfilter-aspect and vsfilter-blur-compat options
The naming for "blur-compat" was misleading since the setting
actually affects more than just blur affects. Additionally
forwarding storage resolution but forcing an aspect ratio
of 1.0 for the video is likely to result in odd rendering
and there’s no known usecase for it.

Both options control which video properties are exposed to libass
so to fix the aforementioned issues merge these settings into one
tri-state sub-ass-use-video-data.

The default V keybind now cycles through all states of
use-video-data instead of toggling vsfilter-aspect-compat.

Resolves: https://github.com/mpv-player/mpv/issues/10680
2024-09-13 23:24:08 +02:00
Kacper Michajłow 5edc8973eb various: use talloc_replace 2024-09-08 17:33:27 +02:00
Kacper Michajłow e7f153db58 stats.lua: don't use ASS tags when use_ass is false
Fixes terminal output.
2024-09-08 17:33:03 +02:00
nanahi f92d5da89c player/main: uninit input after terminal uninit
The terminal input thread holds the input_ctx reference.
Fixes: c1282d4d43
2024-09-08 17:14:37 +02:00
nanahi f02b8bc9fd stats.lua: fix text size/alignment for key bindings page
After a subject line, the text style needs to be reset to make
sure that key binding lines have correct size and alignment
while scrolling the page.
2024-09-05 14:06:05 +02:00
Guido Cella 7c672e33a5 command: expand ~ paths in load-config-file
Fixes #14766.
2024-08-30 18:54:37 +02:00
Kacper Michajłow 938938a985 fuzzer_options_parser: add options parser fuzzing
To improve coverage of parse_commandline.c
2024-08-27 01:31:40 +02:00
Guido Cella 64a0e31aa9 console.lua: pre-filter searched commands if the line is filled
If you type something before pressing Ctrl+r, filter the commands
containing the typed line.

fuzzy_find() is modified to not code a separate case when the line is
empty in both handle_edit() or search_history().
2024-08-24 03:14:04 +02:00
verygoodlee e3a9ce22f9 console.lua: add numpad + - * / keybindings
numpad + - * / was remapped to KP_ADD/KP_SUBTRACT/KP_MULTIPLY/KP_DIVIDE in #14660
2024-08-21 14:31:01 +02:00
Guido Cella ebc14a58ae console.lua: implement history search 2024-08-16 18:32:58 +02:00
Kacper Michajłow 9978cb821d player/loadfile: don't clear watch later for auto playlist parent file
Fixes: https://github.com/mpv-player/mpv/pull/14555#issuecomment-2282338707
2024-08-11 21:06:13 +02:00
Kacper Michajłow ff1f8baecd common/playlist: add playlist_set_current() 2024-08-10 23:27:40 +02:00
Kacper Michajłow 73b58722e7 player/misc: add str_in_list() and use it 2024-08-10 23:27:40 +02:00
Kacper Michajłow 44a3a3293f options: add --{video,audio,image}-exts 2024-08-10 23:27:40 +02:00
Kacper Michajłow 4f1e9e34c3 demux_playlist: add --directory-filter-types 2024-08-10 23:27:40 +02:00
Kacper Michajłow c54ad6933b demux_playlist: add --autocreate-playlist-{video,audio,image}-exts 2024-08-10 23:27:40 +02:00
Kacper Michajłow bb9b862f0c demux: add --autocreate-playlist 2024-08-10 23:27:40 +02:00
Mike Will 88885c0401 audio: add pitch-shifting feature
Uses resampling in tandem with a time-stretching audio filter to
change the audio's pitch while leaving its tempo intact.
2024-08-07 22:56:17 +02:00
nanahi 0818f6001c console.lua: guard user-data/osc/margins value
Defaults margins to 0 if an external script sets this to an invalid value.
2024-08-06 20:28:44 +02:00
Guido Cella ee05804bfa {osc,select}.lua: show playlist entries with trailing /
If a playlist entry ends with a slash these scripts only show the
basename which is empty. Fix this by stripping trailing slashes so that
the last directory component becomes the basename.
2024-08-06 20:27:33 +02:00
Kacper Michajłow ec40dcca9b loadfile: fix relative file open exclusion for fuzzing 2024-08-04 21:33:36 +02:00
Guido Cella 5f768a688b loadfile,select.lua: print only one bitrate
Print demux-bitrate if available, else hls-bitrate, not both (as
demux-bitrate is generally more reliable). This avoids printing "HLS
kbps" which looks weird.

Fixes
https://github.com/mpv-player/mpv/pull/14453#discussion_r1700550385
2024-08-02 08:41:43 +02:00
llyyr 11ed012c34 player/audio: invert audio_started boolean
Waiting for audio_started to be set to true takes too long which causes
us to miss it for the first frame, instead invert the condition so it's
set on the first frame.

Fixes #14615
2024-08-01 11:45:13 +00:00
Kacper Michajłow 5fed12e025 win32: add Media Control support
Add support for SystemMediaTransportControls interface. This allows to
control mpv from Windows media control ui.
2024-07-29 21:38:19 +02:00
nanahi fc6aa2cc8a player/scripting: remove outdated comment about posix_spawn
The comment was added in e2ab6b7f35,
but posix_spawn usage was removed in 5309497727
to ensure CLOEXEC correctness.
2024-07-29 21:00:48 +02:00
Guido Cella 544240c829 player/command: fix --force-window=yes acting like immediate
player/main.c runs all option callbacks with a flag on init, so since
a5937ac7e3 which added UPDATE_VO, if --force-window=yes is passed, the
VO is immediately initialized, as if --force-window=immediate was
passed. Fix this by not running the UPDATE_VO code when there is no
video output.
2024-07-29 01:46:21 +00:00
Guido Cella 6107112b32 player: don't decrement --ab-loop-count=N and add remaining-ab-loops
Follow up to the previous commit. Stop decreasing --ab-loop-count=N on
each iteration so it is preserved across different loops. In particular
it is preserved between different files without adding it to
--reset-on-next-file. Add a property to expose the remaning A-B loop
count instead.

The current behavior of --ab-loop-count=N is even worse than --loop-file
since it also doesn't reset when defining a new A-B loop in the same
file. Defining it has no effect after --ab-loop-count has decreased to
0, and this can't be fixed by adding it to --reset-on-next-file. This
commit also resets remaining-ab-loops every time --ab-loop-a and
--ab-loop-b are set to fix this.
2024-07-26 20:09:19 +02:00
Guido Cella f411f3145b player: don't decrement --loop-file=N and add remaining-file-loops
This stops decreasing numerical values of --loop-file on each iteration
so that loop-file=N loops every playlist entry without having to add
--loop-file to --reset-on-next-file.

The current behavior confuses users as seen in:

https://github.com/mpv-player/mpv/issues/2481
https://github.com/mpv-player/mpv/issues/5943
https://github.com/mpv-player/mpv/issues/11291
https://github.com/mpv-player/mpv/issues/13860
https://www.reddit.com/r/mpv/comments/rcwnrw/looping_each_file_n_times_in_a_playlist/

Also options are supposed to reflect the value configured by the user
and not change on their own.

A remaining-file-loops property is exposed as a replacement to check how
many loops are left.
2024-07-26 20:09:19 +02:00
Kacper Michajłow 397212ae15 player: remove empty line from --help
Follow-up after 127b6a3455.
2024-07-26 20:07:30 +02:00
Guido Cella a5937ac7e3 m_option: add UPDATE_VO flag
This will allow reiniting the VO when more options are changed without
hardcoding them in options.c

Also reinit the VO when changing --gpu-debug and --gpu-sw.
2024-07-24 18:44:41 +00:00
Guido Cella d384a6b793 external_files: allow specifying --cover-art-whitelist filenames
Fixes https://github.com/mpv-player/mpv/discussions/14520.
2024-07-23 14:12:11 +00:00
Guido Cella 8110bdac6d command: remove deprecated packet-*-bitrate properties
These have been deprecated for 9 years so it's fine to remove them.

Using the replacement properties like video-bitrate in stats.lua will
convert big enough bitrates to Mbps.
2024-07-18 22:52:35 +02:00
Guido Cella 5f8ac5b862 loadfile,select.lua: print bitrates of tracks 2024-07-18 22:52:35 +02:00
Guido Cella 7bcd525dce various: sync shown track flags
Show the same flags in loadfile.c, select.lua and stats.lua. The only
differences are that only stats.lua prints both image and albumart
because it's supposed to show detailed track information, and select.lua
prints the image flag because pressing g-v doesn't show Video or Image
like in loadfile.c and stats.lua.
2024-07-18 22:52:35 +02:00
Guido Cella 2fd88ffbae various: print Image instead or Video for image tracks
Fixes #8561.
2024-07-18 22:52:35 +02:00
nanahi 21df853624 osc.lua: don't hide osc when touch is active
This lets touch events activate a separate timeout for osc hiding so that
the osc only hides when both mouse and touch timeout are expired.
This is the general expectation with touchscreen UI, and also fixes
platforms which reset the mouse position when all fingers leave the
touchscreen (e.g. sway).
2024-07-18 22:49:51 +02:00
llyyr 127b6a3455 player: remove empty line from --version 2024-07-18 22:49:28 +02:00
nanahi 58f3009b80 playloop: move run_command_opts to command_event for playback-restart 2024-07-17 18:28:56 +00:00
nanahi 503a896d1a command: run input commands after idle state is ready
This makes sure that commands like show-text update the osd properly
with --idle=yes.
2024-07-17 18:28:56 +00:00
Kacper Michajłow 607ad8943b player/command: don't return ill-formed node if there is no default val
option-info/<name>/default-value would be initialized with zeroed
object, which is not valid for string typed options, as the would be set
to NULL.

Found by OSS-Fuzz.
2024-07-16 22:59:23 +02:00
Kacper Michajłow 0018227b44 player/command: fix M_PROPERTY_KEY_ACTION for filter metadata
tag_property() expect metadata to not be NULL on M_PROPERTY_KEY_ACTION.
M_PROPERTY_GET_TYPE can be skipped only if key is not queried.

Fixes: a05b847879
2024-07-14 01:17:32 +02:00
Kacper Michajłow 0aebcbcc19 player/{command,scripting}: log subprocess execution
Useful for debugging purposes and sanity checks.

Remove unused function while at it.
2024-07-12 22:40:02 +02:00
Misaki Kasumi f2e7146cb1 sub: add (sub/osd)-border-style; renaming sub options 2024-07-12 20:17:38 +00:00
Kacper Michajłow c0f5d2391b ytdl_hook.lua: fix hook triggering while it shouldn't
Fixes: acbd537dac
Fixes: #14522
2024-07-12 11:11:54 +02:00
Kacper Michajłow c505f77dda player/core: add core thread handle to MPContext
This change removes convoluted core thread extraction through dispatch
added in 500ce69a06.

Currently we fully control this thread, create it and join, there is no
reason not to keep the handle of it in the player context.

As a bonus to code simplification this also fixes thread handle leak on
Windows.

Fixes: #14472
2024-07-11 21:55:21 +02:00
Kacper Michajłow b13642e115 player/loadfile: prevent fuzzers from loading absolute directories
It's waste of time to load external files. And it is not deterministic.

Note we still allow to load single files by name, but it is not a big
deal.
2024-07-11 03:48:25 +02:00
Kacper Michajłow aea5b3dbea player/loadfile: cancel playback cleanly if thread fails to start
Currently it would crash, due to already canceled and freed resources.
2024-07-11 03:48:25 +02:00
Kacper Michajłow acbd537dac ytdl_hook.lua: allow changing try_ytdl_first during runtime
Check value in hook instead of hooking conditionally.
2024-07-07 02:32:48 +02:00
verygoodlee bcc72f97ef stats.lua: active key bindings: identify prefix nonrepeatable
The nonrepeatable prefix was added at commit bc5863a
2024-07-05 16:42:31 +03:00
Guido Cella e07470adc2 console.lua: restore the order of items after clearing the input line
When you type something in select mode and then delete it, table.sort
changes how selectable items are sorted. Restore the order specified by
the mp.input caller in this case.
2024-07-04 22:24:10 +00:00
Guido Cella 97af5c98f4 console.lua: minor tweaks
- Remove the opts comments because they are already in console.rst and
  will become outdated if not updated in both places
- Reuse last_pos in truncate_utf8() instead of recalculating the
  previous character's position
- Clear the OSD earlier when the console is not active
2024-07-04 22:24:10 +00:00
Guido Cella 49afdb9365 console.lua: remove the scale script-opt
This is redundant because you can set font_size and border_size to have
the same effect.
2024-07-04 22:24:10 +00:00
nanahi b09e48e388 player/loadfile: enable streams in order of types when loading file
The previous commit to avoid refresh seeking video streams has an edge
case when enabling tracks when loading files. Since the streams are
initially unselected and then multiple streams are enabled, the detection
only works reliably when video tracks are enabled first.

This makes sure that loading file enables tracks in a predictable order.
2024-07-04 22:23:27 +00:00
Guido Cella dc523b137f video/out/gpu/context: convert --gpu-api to object settings list
This follows up 96e1f1dfa5 which converted --gpu-context, and has the
same advantages as listed there.

Unlike with --gpu-context auto can be used anywhere in the list, e.g.
--gpu-api=d3d11,auto works.

I wanted to use the list of GPU contexts as the description in
get_type_desc(), but there is no talloc context to allocate it to, so I
set a print_help_list to print them. The APIs go before the contexts so
that etc/_mpv.zsh doesn't try to complete the contexts.
2024-07-04 22:23:17 +00:00
bashonly e78e2c73cf ytdl_hook: strip quotes from cookie values 2024-07-04 19:10:37 +00:00
Kacper Michajłow 4969d6e03e player/lua: restore original lua allocator before close
We wrap the default Lua allocator to allow used memory tracking. This
works well, except that we never destroy the default allocator or notify
it that we are closing. Since we override it for the current Lua state,
it is reasonable that the Lua engine does not expect it to be used. We
get and pass through a free call, but in the case of LuaJIT, the
internal allocator has additional state and is freed differently. So, in
fact, it is a LuaJIT leak because once we replace the allocator with our
custom one, they should clean its internal state. I guess the assumption
is to override allocator only before any allocation happen. To work
around this issue, restore the default allocator, the one that we use,
before closing the state. This way, everything is cleared as expected.

Note that the current solution of wrapping the default allocator works
only because none of the supported Lua engines actually invalidate the
allocator on the lua_setallocf() call. However, they could, so keep in
mind that we are currently depending on an implementation detail.

Thanks to @Dudemanguy for help with finding the changes that introduced
the leak.

Fixes: a67bda2840
Fixes: #14451
2024-06-30 21:15:37 +02:00
Kacper Michajłow a3f72ea87c stats.lua: fix codec-profile position for audio 2024-06-27 20:24:13 +02:00
Kacper Michajłow 7fb7e1dd73 various: add more format specifiers checks 2024-06-25 05:29:46 +02:00
Dudemanguy 0db6abadd4 playlist: let playlist-next go to first item if player is idle
Similar to the previous commit but the other way around. If you start
mpv as idle, load up a playlist without immediately hitting play and
then try to go to the next item, nothing happens. Naturally, you would
expect this to go to the first item. Fix this detecting if the playlist
has not started yet, the direction, and going to the first item in the
list.
2024-06-25 02:19:08 +00:00
Dudemanguy 0f76848e5f playlist: let playlist-prev go to last item in playlist
Previously, playlist-prev didn't work if you played a playlist to
completion using --idle and tried to go back. Naturally, one would
expect this to bring up the last item in the playlist, but nothing
happens. This is just because playlist_get_next is stupid and doesn't
take this into account since pl->current is NULL and thus returns NULL.
Fix this by considering the direction, checking if the playlist was
played to completion and grabbing the last entry in the index.
2024-06-25 02:19:08 +00:00
Guido Cella 01330dba71 console.lua: assume non-ASCII characters span 2 cells for truncation
This prevents line wraps in select mode with terminal output which hide
the top items (OSD output no longer uses truncate_utf8 since the
previous commit). This is not ideal as even accented letters are assumed
to be 2 cells wide. The alternative is using \e[?7l and \e[?7h to
disable and enable text wrapping, but it won't work in Windows console
with VT processing disabled.
2024-06-24 21:30:14 +02:00
Guido Cella 06cfdc80a6 console.lua: let libass clip lines in select mode
In select mode and when printing the OSD, use \q2 to let libass clip
lines longer than the OSD. This works around having to leave a large
horizontal space unused due to libass subtracting the left margin from
the max text width even though the ASS event is anchored to the bottom
left. It also fixes truncating wide Unicode characters.
2024-06-24 21:30:14 +02:00
Guido Cella ad6bca9c31 console.lua: subtract --osd-margin-x in the max width calculation
Even if ass:pos() hardcodes the position at 6px from the left, we still
need to subtract the left --osd-margin-x from the available text width.
See how libass/ass_render.c:ass_render_event() subtracts it from
max_text_width without checking if the event is positioned.

The calculation is still not perfect as the width could be made a bit
larger before the text wraps.
2024-06-24 21:30:14 +02:00
Guido Cella 82ffe8f425 loadfile: update the format of terminal track information
Stop making unselected tracks and editions grey because they can be hard
to read over a dark background (\033[2m would be hard to differentiate
from regular text with a light theme instead), and because there is no
way to not print the escape sequences in --log-file.

Just use the same circles as the OSD and OSC. We need to print the empty
circles for alignment on mlterm with East Asian fonts (we could also
make them invisible with \033[8m but it would still get added to log
files).

Add back the space before tracks and editions when printed after
"Playing..." or "Track switched" and similar, so they look like a
sub-section of it, consistently with the metadata which starts with
space which makes it look like a sub-section of the "File tags" line.

Leave 2 spaces between track columns.

Make the lang options only as long as the longest language.

Place hls-bitrate within the same parentheses as the other data.

Replace the incomprehensible (*) (f) and [P] with textual descriptions
within []. Also place external there.

Stop converting Hz to kHz for consistency with other log messages, e.g.
AO: [pipewire] 48000Hz stereo 2ch floatp

Remove the space in "2 ch" so it doesn't look like 2 separate values (We
considered using mp_chmap_to_str(&s->codec->channels) but it prints
values like "unknown2").
2024-06-24 16:19:31 +02:00
Dudemanguy 26029cfbb0 m_option: add a way for aliases to use sub option prefix
Previously, using m_option_type_alias required that the alias have the
full name of the option value. This is limited if you are reusing the
same opts struct in different sub options. Fix this by add an additional
field to m_option to signal whether or not prefixes should be taken into
account for the alias option. Instead of blindly using whatever is
stored in opt->priv as the name, we can construct the desired option
name for either case (using the prefix or not).
2024-06-24 12:51:28 +00:00
Kacper Michajłow 5b3b2273db player/command: limit user-data name splits to 100
It fixes stack-overflow with keys that contains hundreds of splits. 100
is more than enough for any valid use of user-data, normally key
shouldn't contain more than a few splits.

Found by OSS-Fuzz.
2024-06-24 03:05:09 +02:00
Kacper Michajłow 799137a87c fuzzers: disallow include command in more principal way
We should never allow include command for fuzzers and it can be
triggered also by direct set property.
2024-06-24 03:05:09 +02:00
Guido Cella 8873beabc3 select.lua: consider --sub-delay for the subtitle line selector
Preselect and seek to the correct subtitle line when there is a
sub-delay.

Also slightly increase the offset without a video track else it
occasionally doesn't seek to the selected line with non-0 sub-delay and
no video. This now uses the same offset as sub/sd.h.
2024-06-22 13:42:27 +00:00
Guido Cella e3f496dbf5 select.lua: don't use sub-start to preselect subtitle lines
There is no need to compare sub-start now that we don't check for exact
matches with ffmpeg's timestamps. time-pos can always be used.

Comparing time-pos removes the need for the workaround of sub-start of
embedded subtitles being earlier than ffmpeg's timestamps, as time-pos
is always slightly after sub-start.

Removing this workaround also fixes a bug present since 4059d1832b,
which started comparing numerical values of timestamps instead of
strings to determine the preselected subtitle line, where the line after
the current one is preselected when sub-start is greater than ffmpeg's
timestamps because they have been rounded, e.g. sub-start 10.001 is >
than ffmpeg's 10.00.

This will also allow considering --sub-delay in the comparisons, as
comparing sub-start - sub-delay would preselect the wrong lines.
2024-06-22 13:42:27 +00:00
Dudemanguy 23ecfa9845 options: remove deprecated auto choice for --mute
Since 995c47da9a, setting --mute=auto has
been equivalent to --mute=no. It was formally documented later in
79e20ff485. This is an old legacy relic
and the auto choice popping up during auto completion could be confusing
to users who aren't aware of the history. Remove it for good and convert
the option to a proper boolean.
2024-06-21 21:29:33 +02:00
Dudemanguy bab9b2cf4e player/command: alias playback-time to time-pos
Since 7fc4bac29f, playback-time and
time-pos will now always have exactly the same values. Both properties
are commonly used, so just make playback-time an alias for
time-pos and document it.
2024-06-20 13:07:41 +00:00
nanahi 8df4cb5e21 osc.lua: don't use legacy argument for seeking
Deprecated since mpv 0.9. Use the flags instead.
No need to specify flags for relative seek since it's the default.
2024-06-19 01:30:18 +00:00
Crend King c9ea2798a4 osc.lua: add script message to show up the OSC
Add a way to briefly show the OSC, which is useful to check file name,
playback progress and time left, etc.

Fix issue #3826
2024-06-16 01:23:38 +02:00
Guido Cella eae74bdb7a osc.lua: replace tabs with spaces
Fixes b6d7f778b8.
2024-06-16 01:21:55 +02:00
Kacper Michajłow a41cdf0289 stats.lua: align 100% correctly on page 2
It is not common to have one pass with 100% usage, but it is not
impossible, so handle this case too.
2024-06-14 00:26:04 +02:00
Guido Cella 5158a3d779 console.lua: don't enable the console-input input section
https://github.com/rossy/mpv-repl enabled and disabled its keybindings
with input sections (define-section, mp.enable_key_bindings and
mp.disable_key_bindings), but when wm4 merged it in mpv, he changed it
to use mp.add_forced_key_binding and mp.remove_key_binding because he
deprecated input sections, but he forgot to remove the
mp.enable_key_bindings line. Remove it now.
2024-06-09 20:50:03 +02:00
nanahi 22103b8a8f osc.lua: fix timetotal and timems settings 2024-06-09 06:08:10 +02:00
nanahi d2bd77ada0 stats.lua: display file tags
This adds file tags to display along with the title, including
album/artist etc. for music, and series etc. for some videos.
The list of tags to display is identical to the tags printed to
the terminal and is controlled by the --display-tags option.

To filter out overlength tags (such as long comments and lyrics) and
files with too many tags, add file_tag_max_length and file_tag_max_count
options so that tags longer than this length are not displayed, and only
the first few tags are displayed.

Also makes tags show on page 5 only.
2024-06-09 00:58:48 +02:00
Guido Cella 948faa5482 lua: don't pass nil as the second argument of mp.get_property_number
This doesn't do anything because nil is already the default value of
unavailable properties.
2024-06-08 23:10:37 +02:00
Guido Cella 1a5edb1e49 stats.lua: remove print_perfdata_passes
22a8b99 introduced print_perfdata_passes as a stopgap until a dedicated
performance stats page would be implemented. Since it has been
implemented for many years, remove this option, which isn't even
documented, and is likely to make the stats overflow beyond the screen.
2024-06-08 23:07:17 +02:00
Kacper Michajłow 73e779a1ee stats.lua: add page 5 for currently selected tracks information 2024-06-08 23:06:22 +02:00
nanahi 6679ef003e stats.lua: make the append function increment index only on newline
To avoid a large append parameter refactoring is to make the append
function add the table index only if the newline character is not empty.
Otherwise, new strings are appended to the existing string.
2024-06-08 23:06:22 +02:00
nanahi f8f47d06f4 osc.lua: add option to use display fps for update interval
If the display fps is unavailable, use the tick_delay as a fallback.
2024-06-08 13:46:11 +02:00
nanahi fa525265b4 osc.lua: unify observe_property style 2024-06-08 13:46:11 +02:00
nanahi 6337bc27ff osc.lua: add option to make rendering smoother
OSC rendering used to be smooth (up to OSD rendering fps) before
48f906249e, but after that commit the
frame duration is hardcoded to 30 ms. This is too high and results in
choppy OSC rendering, which is very noticeable with the progress bar
while moving mouse over it or playing a short 60 fps video.

This makes the duration an option so that it can be decreased to make
OSC rendering smoother.
2024-06-08 13:46:11 +02:00
Guido Cella dc998560aa options: add --osd-playlist-entry
Allow configuring whether to print the media-title, the filename or both
(as `<title> (<filename>)`) in show-text ${playlist}, the OSC playlist
and in the playlist selector.

Showing only titles hides information when files are badly tagged, or
when it hides the track numbers of album songs. But showing filenames is
not as useful as titles e.g. when playing URLs with media titles. This
option lets the user choose which one to show, or show both if switching
is inconvenient.

The OSC's playlist_media_title script-opt is removed because this option
is better since it works everywhere after configuring it once.

Closes #11653.

Also show the full URLs of playlist entries instead of their basenames
in osc.lua and select.lua, consistently with mp_property_playlist().

For simplicity, this just checks if entries contain :// instead of
replicating all of mp_is_url().

Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2024-06-08 01:43:15 +02:00
Guido Cella 2becb971e9 console.lua: prettify unselected track log messages
After d49879f1f7 terminal escape sequences are printed in the console
log for unselected tracks. Remove them and make those lines grey.
2024-06-07 22:47:44 +02:00
Guido Cella 75645263dd select.lua: support extracting ytdl_hook subtitles
They don't work because they have EDL URLs, but we can attempt to
extract their real URLs.
2024-06-07 22:45:41 +02:00
Guido Cella 5657cd65b7 select.lua: hide the hour when it's 0
Omit the hour in the chapter and subtitle line selectors when the file
is shorter than an hour.
2024-06-07 22:45:41 +02:00
Guido Cella 8939bfc3ef select.lua: seek to the currect subtitle line when paused without video
Add an offset to sub seek correctly like in b35e34ae2f. The extra 0.01
offset apparently isn't necessary in this case.
2024-06-07 22:45:41 +02:00
Guido Cella 4059d1832b select.lua: preselect the correct sub line with duration >= 100 minutes
ffmpeg outputs timestamps like '100:00.00' in LRCs instead of adding
hours, and timestamps like '100:00' are < '10:00', so since these
strings are being compared, if there is no current subtitle line, there
are subtitle lines at >= 100 minutes, and time-pos is between 10 minutes
and 100 minutes, one of the last subtitle lines gets preselected.

Fix this by converting the timestamps to numbers before comparing them.

Also simplify the logic by merging the 2 loops to determine the default
line, and reformat the timestamps by adding hours to not print minutes >
60 in the selector, and by removing the hundredths of seconds. This
requires storing the accurate timestamps in a table to seek to them on
submit.
2024-06-07 22:45:41 +02:00
Guido Cella d49879f1f7 loadfile: improve the format of terminal track information
Print vlang if present.

Make unselected tracks and editions grey instead of adding (+) before
selected tracks. Mark them with the same circles as show-text
${track-list} and script-message osc-tracklist when not outputting to a
TTY.

Don't print a different symbol with --sub-forced-events-only because
nobody uses this option, and subtitles are very unlikely to mix forced
and non-forced events.

Align 2-digit track IDs.

Align languages of up to 7 characters (the length of zh-Hans).

Leave spaces when a track has no language but at least another track
does to align the following track data with the other tracks.

Add a space between values and their units.

Convert Hz to kHz.

Pretty print FPS and kHz with mp_format_double().

Don't print images' FPS because it's just a bogus value taken from
--mf-fps.

Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2024-06-07 22:24:25 +02:00
UNIVPM-S1079707 b6d7f778b8 osc.lua: fix user configurable colors 2024-06-07 19:45:46 +02:00
nanahi 31ae111ff5 default.js: handle canceled key bindings 2024-06-06 23:38:39 +03:00
nanahi eeb8e6e451 defaults.lua: handle canceled key bindings
There is a subtle behavior difference for built-in/input.conf key bindings
and key bindings registered by scripts: when a key binding is canceled
(e.g. a mouse button is bound to a command, is pressed down, and then
another key is pressed which is bound to another command), the command is
not invoked if the binding is built-in/input.conf, but is invoked if it's
registered by scripts, because it's handled with a different mechanism,
which gives no way for scripts to detect this.

Fix this by using the newly available canceled flag to detect this.
If a key binding is canceled, the callback is now not invoked unless
the key binding is registered with the complex option. In this situation,
the callback is invoked with the canceled state available so that scripts
can detect and handle this situation.
2024-06-06 23:38:39 +03:00
nanahi 5fcbe1c417 command: add canceled state to key-binding client message
This allows libmpv clients to know whether the key binding is canceled
and thus should normally be ignored.
2024-06-06 23:38:39 +03:00
Kacper Michajłow f40b569426 player/main: concat string at compile time 2024-06-05 19:16:35 +02:00
Dudemanguy fa89082f2e sub: avoid unneeded calls to is_animated
4e5d996c3a added this as part of a series
of patches written to avoid wasteful sub redraws when playing a still
image with subs. The is_animated special case was specifically for ASS
subtitles that have animations/effects and would need repeated redraws
in the still image case. This check was done unconditionally for all ASS
subtitles, but for very big ASS subtitles, this text parsing can get a
bit expensive.

Because this function call is only ever needed for the weird edge case
of ASS subtitles over a still image, some additional logic can be added
to avoid calling is_animated in the vast majority of cases. The animated
field in demux_packet can be changed to a tristate instead where -1
indicates "unknown" (the default state). In update_subtitle, we can look
at the current state of the video tracks and decide whether or not it is
neccesary to perform is_animated and pass that knowledge to sd_ass
before any subtitle packets are decoded and thus save us from doing this
potentially expensive call.
2024-06-04 12:29:13 +00:00
Kacper Michajłow d70a0b4494 player/playloop: remove now unused get_percent_pos() 2024-06-03 19:16:35 +02:00
Kacper Michajłow 37127276cc win32: quantize taskbar playback position into uint8 range
Also, if the position is valid, set it to 1 / INF. Windows interprets 0
as non-progress.

Progress is quantized into uint8 range, it is good enough for this
use-case. This avoids unnecessary vo_control and
ITaskbarList3::SetProgressValue calls and should be visually
indistinguishable in practice.

Fixes #14282
2024-06-03 19:16:35 +02:00
nanahi cfc651a805 osd: don't use get_percent_pos function
Use get_current_pos_ratio instead, and round the value to integer with
printf precision specifier.
2024-06-03 15:14:40 +02:00
nanahi b77c5168b4 command: simplify printing floats as integers
For this purpose, the printf precision specifier can be used.
No need to call lrint.
2024-06-03 15:14:40 +02:00
Guido Cella 525fa85932 osc.lua: fix lint warnings 2024-06-02 22:26:00 +02:00
Guido Cella 62868beffe ytdl_hook.lua: fix lint warnings 2024-06-02 22:26:00 +02:00
Guido Cella fe760f2b8a console.lua: fix lint warnings 2024-06-02 22:26:00 +02:00
Dudemanguy 5988473b76 player: replace get_current_time with get_playback_time in some spots
The problem with using get_current_time is that it can return negative
values. Interally in mpv, we need this but for some spots negative
values are not great. Since the previous commit enforced nonnegative
returns for get_playback_time, we can use that instead. The two areas
changed here are watch later configfile writing (clearly should always
be a positive number) and the time-pos property (negative numbers are
nonsense for users). This fully fixes #10346.
2024-05-29 13:48:40 +00:00
Dudemanguy d93f53b324 player/playloop: force get_playback_time to be at least 0
Except for MP_NOPTS_VALUE. We keep that as is. When this was originally
added in a73415584c, it appears like
having the time always start at 0 was the intent. In cases where
get_current_time returns a negative that isn't MP_NOPTS_VALUE, force
this to 0.
2024-05-29 13:48:40 +00:00
Dudemanguy 652036ba54 player: put speed adjustment back into playing_audio_pts
Effectively reverts 7051e94e4b. There's
been some confusion with how audio pts gets used internally in mpv which
leads to weird results. The crux of the problem is essentially that
playing_audio_pts can return negative numbers and in many places this is
not expected. This is the first step in trying to hopefully iron out all
the weird corner cases.
2024-05-29 13:48:40 +00:00
nanahi eaae9e9cf5 player/video: fix incorrect VO frame duration and frame drops
The logic in question was added in 201bef7ee1
for the VDPAU vsync frame timing algorithm, but after the code was moved
around for several times, it is now used for all VOs with non-display-sync
mode (where the video is synced to audio or system time). It nonetheless
likely never did whatever it was intended for.

This "correction" reduced the VO frame duration by the amount that the
frame is fallen behind the ideal time. Since a frame is presented between
pts (the ideal time for which the frame is scheduled) and pts + duration
(the end time for which frame drop is determined), and pts is already
computed from the current time and the deviation from the ideal time, this
"correction" causes the end time to have the deviation added twice, which
is nonsense: if the deviation is -0.5x the frame duration, the frame is
dropped, even though it should be displayed from now to 0.5x the frame
duration from now.

It was not noticed at that time probably because the VDPAU secret rabbit
code undid some of its damage, and the subsequent development focus on
display-sync modes resulted in negligence and simplification of audio mode
(e.g. b8bcf0f466), but the generic VO frame
drop algorithm has been observed to cause inconsistent frame drops with
this "correction": playing a 59.94 Hz video at 2x speed on a 60 Hz display
results in spending over half of the time dropping adjacent frames instead
of every other frames, visually causing stuttering, while it should only
happen briefly when the pts is very close to vsync time.

Fix this by deleting this logic, making the VO frame always having the
duration of the video frame.

Fixes: 201bef7ee1
2024-05-29 13:39:32 +00:00
Guido Cella 15ea0d1987 console.lua: fix crash with set ;<Tab>
Fixes https://github.com/mpv-player/mpv/pull/14247#issuecomment-2134418206
2024-05-28 13:25:37 +00:00
nanahi 75f252c47c console.lua: fix crash if no completions exist
If complete is case-sensitive and no completions exist the script crashes
with the following:

Lua error: @console.lua:1417: attempt to concatenate local 'prefix'
(a nil value)
2024-05-28 13:24:16 +00:00
Guido Cella 021c5dedb1 playloop: don't loop when seeking to the end of cover art while paused
Fix the bug that seeking to the end of cover art while paused goes back
to the beginning of the file because of this condition meant for videos.

This doesn't check mpctx->vo_chain->is_sparse because prevent_eof should
be true with actual sparse videos.
2024-05-26 14:23:57 +00:00