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

Prefix the "ytdl-format" argument value by "best[height<=${opts.maxheight}]/" #35

Open
sebma opened this issue Sep 11, 2020 · 8 comments

Comments

@sebma
Copy link

sebma commented Sep 11, 2020

Hi,
Can you please update the --ytdl-format argument value in your ../chrome-extension/background.js according to this git diff output so that format selection on https://ok.ru/video can work :

$ git br 
* master
$ git describe --tags --abbrev=0
0.1.0
$ git diff chrome-extension/background.js
diff --git a/chrome-extension/background.js b/chrome-extension/background.js
index 799d99d..4de29e8 100644
--- a/chrome-extension/background.js
+++ b/chrome-extension/background.js
@@ -25,7 +25,7 @@ function playUrl(url, pause) {
                }
                if (opts.maxheight) {
                        opts.mpv_args.splice(0, 0,
-                       `--ytdl-format=bestvideo[height<=?${opts.maxheight}]+bestaudio/best`);
+                       `--ytdl-format=best[height<=${opts.maxheight}]/bestvideo[height<=?${opts.maxheight}]+bestaudio/best`);
                }
                const query = (`?play_url=` + encodeURIComponent(url) + [''].concat(
                        opts.mpv_args.map(encodeURIComponent)).join('&mpv_args='));

I tried modifying this file myself within the browser extension directory, but chrome says This extension may have been corrupted. and thus disabled this extension.

@Chaostheorie
Copy link

Kinda late but would you mind if I open a pull request with your changes?

Chaostheorie pushed a commit to Chaostheorie/play-with-mpv that referenced this issue Apr 7, 2021
While I'm at it why not attempt to fix Thann#35 too
@sebma
Copy link
Author

sebma commented Apr 9, 2021

@Chaostheorie Thanks. We'll have to check if this commit works when playing videos on https://ok.ru/video with the current youtube-dl version.

@Haxprox
Copy link

Haxprox commented Apr 9, 2021

In addition to this, would it be great to have a preferred hardware codec option like 'avc1, hevc, vp9/8, etc?
bestvideo[vcodec^=avc1|hevc|vp9|vp8]
Maybe somehow here: https://github.com/Thann/play-with-mpv/blob/master/chrome-extension/options.html with an additional and static field?
But the perfect solution of course is a dynamic option when pressing the button

@Chaostheorie
Copy link

This sounds more like something you would configure with mpv rather than handle with this plugin. Are you sure this is url dependent and can't be passed to mpv/ youtube-dl with a config?

@Haxprox
Copy link

Haxprox commented Apr 9, 2021

Yup, totally agree with you but thinking about size as a static option, codec option can solve other hardware issues when the user experience with lagging by unknown reasons and can choose some additional codec options. But another hand, yes, it's just for the advanced users, of course.
For example:
Having an old intel processor, the hardware is able to handle only h.264 and if I pass '[bestvideo]' options without arguments, I'll get VP9 codec with lagging picture as you actually know :)

@Chaostheorie
Copy link

Chaostheorie commented Apr 9, 2021

Huh, I didn't consider this. Your point is indeed something that should be considered with respect for different setups.
I guess it would be useful to have an option for the extension instead of having this toggled by default to not hurt UX. I will look into integrating this tomorrow/ on the weekend.
Thank you for bringing this to my attention.

Edit: I'm short on time due to some problems with my server. I might take some time to implement this. Sorry for the delay

@Haxprox
Copy link

Haxprox commented Apr 10, 2021

Brilliant, thank you!
The example below is just for your additional attention and review:

  1. Pointing to 4K video and default '[bestvideo]' option we're getting the next result:

~ ➤ mpv --start=1:40 --pause https://www.youtube.com/watch\?v\=LXb3EKWsInQ --ytdl-format="bestvideo+bestaudio/best"
Resuming playback. This behavior can be disabled with --no-resume-playback.
(+) Video --vid=1 () (av1 3840x2160 59.940fps)
(+) Audio --aid=1 --alang=eng (
) (opus 2ch 48000Hz)
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 3840x2160 yuv420p10
(Paused) AV: 00:01:40 / 00:05:13 (32%) A-V: 0.000 Cache: 5.9s/20MB
Saving state.

Exiting... (Quit)

  1. For H.264 option:

~ ➤ mpv --start=1:40 --pause https://www.youtube.com/watch\?v\=LXb3EKWsInQ --ytdl-format="bestvideo[vcodec^=avc1]+bestaudio/best"
Resuming playback. This behavior can be disabled with --no-resume-playback.
(+) Video --vid=1 () (h264 1920x1080 59.940fps)
(+) Audio --aid=1 --alang=eng (
) (opus 2ch 48000Hz)
[vaapi] libva: /usr/lib64/dri/iHD_drv_video.so init failed
Cannot load libcuda.so.1
AO: [pulse] 48000Hz stereo 2ch float
Using hardware decoding (vaapi).
VO: [gpu] 1920x1080 vaapi[nv12]
(Paused) AV: 00:01:40 / 00:05:13 (32%) A-V: 0.000 Cache: 22s/14MB
Saving state.

Exiting... (Quit)

  1. And for VP9:

~ ➤ mpv --start=1:40 --pause https://www.youtube.com/watch\?v\=LXb3EKWsInQ --ytdl-format="bestvideo[vcodec^=vp9]+bestaudio/best"
Resuming playback. This behavior can be disabled with --no-resume-playback.
(+) Video --vid=1 () (vp9 3840x2160 59.940fps)
(+) Audio --aid=1 --alang=eng (
) (opus 2ch 48000Hz)
[vaapi] libva: /usr/lib64/dri/iHD_drv_video.so init failed
Cannot load libcuda.so.1
AO: [pulse] 48000Hz stereo 2ch float
[ffmpeg/video] vp9: No support for codec vp9 profile 2.
VO: [gpu] 3840x2160 yuv420p10
(Paused) AV: 00:01:40 / 00:05:13 (32%) A-V: 0.000 Cache: 2.2s/7MB
Saving state.

Exiting... (Quit)

By default, it returns VP1 which can't be supported by the older hardware.
Most probably a good solution for the default option is H.264, it will get rid of future issue requests :)

@beew
Copy link

beew commented Jul 8, 2021

Can you just add this line to your mpv config file?

ytdl-format=bestvideo[height<=?1080][fps<=?30][vcodec!=?vp9]+bestaudio/best

Works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants