iBicha / UnityYoutubePlayer

Play YouTube videos in Unity
The Unlicense
336 stars 63 forks source link

No Audio in YoutubeDlOptions.Three60 mode #67

Closed Pithakote closed 4 months ago

Pithakote commented 3 years ago

hello,

I'm trying to make a paranomic 360 youtube video player which renders onto a texture for a skybox. everything works just fine but when it's using YoutubeDlOptions.Three60, the audio stops working and it only works with YoutubeDlOptions.Default mode.

This is a problem because I cannot use YoutubeDlOptions.Default because it stretched the texture on the top and the bottom of the skybox and has got some "cuts" in the video as well.

Can anyone help?

Thanks!

jeffries7 commented 2 years ago

This is because Youtube videos over 720p, might be 1080p, don't have audio. The audio for these videos is stored in a different URL. Play around with the YoutubeDlOptions and post the URLs into a web browser to see exactly how it works.

There are 2 ways around this. You could either process a URL twice, once getting the video URL and then another getting a low-resolution video(only using the audio), both being streamed into their own video players. You'd need YoutubeDlOptions something like "bestvideo[height<=?1440]" for video and "worst" for the audio.

The other way is doing pretty much the same but using "bestaudio" or "worstaudio" then using a Unity web request to stream the audio in. This method is more performant as you're not having to stream 2 video feeds in but requires a bit more work.

I needed to do this in my project, I started with the first option as a proof of concept then changed over to the second option to save bandwidth.

Pithakote commented 2 years ago

This is because Youtube videos over 720p, might be 1080p, don't have audio. The audio for these videos is stored in a different URL. Play around with the YoutubeDlOptions and post the URLs into a web browser to see exactly how it works.

There are 2 ways around this. You could either process a URL twice, once getting the video URL and then another getting a low-resolution video(only using the audio), both being streamed into their own video players. You'd need YoutubeDlOptions something like "bestvideo[height<=?1440]" for video and "worst" for the audio.

The other way is doing pretty much the same but using "bestaudio" or "worstaudio" then using a Unity web request to stream the audio in. This method is more performant as you're not having to stream 2 video feeds in but requires a bit more work.

I needed to do this in my project, I started with the first option as a proof of concept then changed over to the second option to save bandwidth.

Thanks for the information!

I made it work using the first method you mentioned on the same day i posted it 😅. I did not know about the second method. Also, could you tell me those keywords "bestaudio" / "worstaudio" "worst" etc, and where can I learn more about them?

Thanks!

jeffries7 commented 2 years ago

Thanks for the information!

I made it work using the first method you mentioned on the same day i posted it 😅. I did not know about the second method. Also, could you tell me those keywords "bestaudio" / "worstaudio" "worst" etc, and where can I learn more about them?

Thanks!

No worries, glad you got it sorted.

You can find more info here and the keywords are located here.

iBicha commented 2 years ago

What @jeffries7 is suggesting is correct. I wanted to avoid adding a "hacky" sample that uses two download urls, one for audio and another for video, because then I will be dealing with countless Github issues related to performance of desynchronized audio and video. Until there's a good way to solve it, I'll leave at that.

But loving the discussion! Please leave these technical hints for others to find, it come useful

iBicha commented 4 months ago

Closing this since the feature for 360 has been removed in version 3.0.0 (please see comment) I apologize for this "reset", if this feature is still important to you, please open a feature request for the 360