Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please don't use powershell Get-Clipboard in console.lua. It can take up to 1x seconds on first run #14373

Open
6 tasks done
Mark-Joy opened this issue Jun 17, 2024 · 4 comments
Labels
meta:help-wanted Anyone is invited to help with this. Suitable for new developers with no experience with mpv code. os:win

Comments

@Mark-Joy
Copy link

Mark-Joy commented Jun 17, 2024

mpv Information

mpv v0.38.0-476-gd2bd77ad Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Jun  9 2024 00:05:18
libplacebo version: v7.349.0 (v7.349.0-rc1-2-gbc9de9c-dirty)
FFmpeg version: N-115628-g658439934
FFmpeg library versions:
   libavutil       59.21.100
   libavcodec      61.7.100
   libavformat     61.3.104
   libswscale      8.2.100
   libavfilter     10.2.102
   libswresample   5.2.100

Other Information

  • Source of mpv: Windows builds by shinchiro
  • Windows version: Windows 10
  • GPU model, driver and version: Intel HD Graphics 530
  • CPU: Intel core i3-6100

Reproduction Steps

  • Restart computer, wait for it to completely boot up. Check Task manager to ensure there is no process hogging CPU/Disk/Ram
  • Copy a text like "Hello World"
  • Open mpv > open mpv console (press `) > Paste clipboard text (Press ctrl+v)

Expected Behavior

The clipboard text is pasted with a small delay, like below 1 second..

Actual Behavior

On my system, the clipboard text took 1x seconds (more than 10 seconds) to be pasted into mpv console on first run.
This is because console.lua uses powershell command to getclipboard data. On first run, powershell can be really slow.

Log File

output.txt

Sample Files

I pressed ctrl+v at 00:13, text showed up at 00:22

mpv-powershell-firstrun.mp4

I carefully read all instruction and confirm that I did the following:

  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
@hooke007
Copy link
Contributor

Do win-users have the better native alternatives to powershell?

@Mark-Joy
Copy link
Author

Mark-Joy commented Jun 17, 2024

Do win-users have the better native alternatives to powershell?

Implement paste function it in C/C++, then export to lua:
https://github.com/sindresorhus/windows-clipboard/blob/0ed96922fd080040135488a9b24be6992155b366/paste.c

int wpaste() {
	OpenClipboard(NULL);

	HANDLE hData = GetClipboardData(CF_UNICODETEXT);
	if (hData) {
		wchar_t *pText = (wchar_t *) GlobalLock(hData);
		if (pText) {
			_setmode(_fileno(stdout), _O_U8TEXT);
			fputws(pText, stdout);
			GlobalUnlock(hData);
		}
	}

	CloseClipboard();
	return 0;
}

or use prebuilt-tool: windows-clipboard or only paste

@kasper93
Copy link
Contributor

Powershell likes to spin up HDDs for some ungodly reason it tries to enumerate them which wakes them up and it can take seconds. I think this is what you see.

I think it is good idea to add internal native method to get clipboard contents, generally spinning up subprocesses in scripts should be avoided, it will always be slower.

@kasper93 kasper93 added the meta:help-wanted Anyone is invited to help with this. Suitable for new developers with no experience with mpv code. label Jun 17, 2024
@na-na-hi
Copy link
Contributor

Native clipboard support is added by #13837. Once the API design is finalized, a win32 implementation can be added. The console then needs to update to use the new API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta:help-wanted Anyone is invited to help with this. Suitable for new developers with no experience with mpv code. os:win
Projects
None yet
Development

No branches or pull requests

4 participants