Closed MTM-A closed 2 years ago
Even on the fastest path - you will still need a few seconds to load the video. You need to make a web request to youtube, download a web page, parse the actual url of the video, and pass that to the video player which will also make a web request, download, decode, and play the video.
That being said, the built-in server in this repo is for demo purposes only, and it is being shared between all users of this repo. Consider How do I host my own youtube-dl server?.
i am already using my own youtube-dl server. could you give me a code example of what you said?
I was only explaining how much work goes into playing the video, and how many back and forth requests happening.
It's an explanation on why it is slow. I do not have a way to make it faster.
You can use YoutubePlayer. PrepareVideoAsync
to do the request to the server before hand, and then play the video when ready.
would there be a method to know how long the video is already ready to be viewed ?? or know if the video has stopped for the load.
another thing, I noticed that the PrepareVideoAsync phase takes 10-17 seconds to complete the operation. Even on a 10 second youtube video it takes a long time and the video freezes if you put play as soon as PrepareVideoAsync finishes. As already said I am using the example project but using my own youtube-dl server as recommended by the guide. It is not a connection problem.
As asked in the previous comment is there a way to show how much video can be played seamlessly?
This seems to be more of an issue with youtube slowing things down. I have the download button available on my project so that end users can download the video and then place it in a directory in which another scene automatically plays from that directory. If you attempt to download with this library, a 15 minute video takes upwards of 20 to 30 minutes to download. Depending on the size of the file at least. So, even loading the video async it takes a long time to start playing. Since you cache a portion of it before playing, that goes quickly and then the video starts to skip as it buffers. The only way to get around this right now is to act like an android player and then the video downloads very fast. 15 minutes was downloaded in less than a second with this library https://github.com/yt-dlp/yt-dlp. I am not sure if it can be directly replaced inside this library. It does act the same as yt-download and changing the executable name to reflect the yt-download one runs the commands like yt-download. Maybe this can be added or the android player emulation added to this library instead. I knew that using this in my project would eventually have issues since the original library would hit a wall every so often when youtube changed whatever they changed in the background.
Thanks a lot for reporting this. Related is #76. I think the fix under yt-dlp might be a workaround, thanks @ubergeekseven for sharing.
The actual answer is right here https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-974052706 and youtube-dl needs to implement one of the solutions.
One thing I noticed is that https://unity-youtube-dl-server.herokuapp.com/watch?v=1PuGuqpHQGo is slow in Unity, but not in Chrome. There might be yet another way.
@iBicha I got the notification that responses were added. I didn't expect you to add that the server itself send to somehow create an issue for this. I thought that your code originated from the YouTubedl project and if you were to try the code from that repository. You would get the same slow download speeds. I have tested this myself and it's definitely an issue using that projects code locally through the command line. No hosted code with it and the speed is exactly the same. When using it in unity before I compile, I can see the speed in the terminal while downloading. Same speed. I have my own hosted site for your code using your example given in the main description. I thought maybe your experience would be linked to your hosted version and the amount it may be used by others. I don't want to impose on your cap and have you spending any money on that.
You mention using it in chrome and not getting the speed problems. I'm not sure how to do that myself. It could be useful to be able to feed YouTube urls from any device and get a download instead of me always using the command line interface with the other repository.
That all being said, once I ran into this issue I looked for a fix and stumbled on the other repository through the comments in the original ytdowload repository. Then I had to start downloading videos to a network share to stream using the built in video player until a fix exists.
Since my project is user facing, the interface cannot be demanding in any way to them. Having the ability for them to go to a specific scene and paste their url and just have it work without calling me is great. Live streaming would be great too if ever possible. I resist to rtsp for that now.
There has been a few changes since this thread:
This should solve the problem, by setting the Cli
option to Yt Dlp
in the inspector in the YoutubePlayer component.
Hi, I'm having a problem playing any youtube video. I downloaded the example project and also in this I find the same problem that is the videos are not smooth and the loading time of a video can take even 7 - 15 sec if not more (especially on smartphones). This happens both on all platforms (Android / iOS and PC) In the console I don't find any exceptions, the connection speed is excellent. I would like to know what it is due to and if it happens to others as well. What do you advise me to do?