Closed davidbernat closed 1 year ago
I don't think we'll create a native component for YouTube videos (although users might be interested in creating custom components, when do that down the line). The best solution I would say is to embed the YT video, which works pretty well for me:
The code here is:
import gradio as gr
embed_html = '<iframe width="560" height="315" src="https://www.youtube.com/embed/EngW7tLk6R8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
with gr.Blocks() as demo:
gr.HTML(embed_html)
demo.launch()
🙏 @abidlabs
gr.HTML
element than the direct urls from e.g. youtube_dl
, is that correct? That does not seem quite accurate, but I do not know video platforms well enough yet.@davidbernat
Will go ahead and close since that seems to answer the question, but feel free to reopen if not!
On first try above embed approach didn't work by copying the URL of the video from Youtube. But after Googling "Embed Youtube Video", there was a mention to right-click on the video and get the embed code from there. Using that code, it worked.
The
gr.Video()
component works using local filenames or urls. But what is the expected use case for embedded video platforms like Youtube? YouTube is protective of its video access urls, as far as I understand this. What has the community been doing?For example, the
youtube_dl
package does provide urls to the direct video codec files, and using those urls does successfully render the video file from the Chrome URL bar. These do not work (as successfully) in Gradio components.I searched the Gradio issues and found no instances of
YouTube
.To clarify: the difficulty of using the video-file url of
youtube_dl
is that YouTube throttles its download speeds. (Here you can see a 2MB video file took 30 seconds.) Appropriate solution is to create an HTML frame, or some equivalent. But that does not answer the question of accessing the data.