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.
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
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.
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.
`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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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().
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.
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
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.
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.
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.
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.
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.
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).
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.
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
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
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.
- 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
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.
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.
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: a67bda2840Fixes: #14451
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.
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.
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.
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.
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.
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").
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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>
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.
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>
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.
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.
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
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.
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.
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.
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
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)
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.