I’m working on a project where I need to show videos stored in my Google Drive directly within my Google Colab environment. I have the sharing link for the video file but I’m not sure how to properly embed or display it in my notebook cells.
I’ve tried a few different approaches but none of them seem to work correctly. The video file is in MP4 format and it’s already shared with proper permissions. I just need to know the right way to reference the Drive URL and display the video content.
Is there a specific library or method I should use for this? Any working examples would be really helpful since I’m still learning how to handle media files in Colab notebooks.
Try the Video widget from ipywidgets - it gives you way more control. After mounting your drive, just import Video from ipywidgets and do: Video.from_file('/content/drive/MyDrive/your_video.mp4'). It handles encoding better than HTML embedding and you get native controls. Install ipywidgets first if you don’t have it. I’ve had better luck with this method for larger files or when I need to control playback stuff programmatically.
hey, i had the same problem! first, mount your drive, then use HTML() from IPython.display. this worked for me: HTML('<video width="320" height="240" controls><source src="/content/drive/MyDrive/your_video.mp4" type="video/mp4"></video>'). just make sure your path is correct!
You can also stream directly from Drive without mounting by using the file ID. Just grab the file ID from your sharing link and use IPython.display.HTML with an iframe: HTML('<iframe src="https://drive.google.com/file/d/{FILE_ID}/preview" width="640" height="480"></iframe>'). Swap {FILE_ID} for your actual file ID. This works great when you don’t want to mount your whole drive or you’re working with files someone else shared. Just make sure the file’s set to “Anyone with the link can view.” I prefer this for presentations since you don’t need local file paths.