Skip to content

Instantly share code, notes, and snippets.

@arundasan91
Created April 14, 2017 19:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arundasan91/a8afa7ffd949dfc099bfdef4e7efb30b to your computer and use it in GitHub Desktop.
Save arundasan91/a8afa7ffd949dfc099bfdef4e7efb30b to your computer and use it in GitHub Desktop.
Function to display any video in Ipython or Jupyter Notebook given a directory in which the video exist and the video file name.
def showanyVideo(baseDir=None,fname=None):
"""Function to display any video in Ipython or Jupyter Notebook given a directory in which the video exist and the video file name.
Args:
baseDir: Directory containing the video
fname: Filename of video.
"""
from IPython.display import HTML
import os
location = baseDir + fname
if os.path.isfile(location):
ext = '.mp4'
else:
print "Error: Please check the path."
video_encoded = open(location, "rb").read().encode("base64")
video_tag = '<video width="320" height="240" controls alt="test" src="data:video/{0};base64,{1}">'.format(ext, video_encoded)
return HTML(data=video_tag)
@caph1993
Copy link

caph1993 commented Dec 7, 2018

Why do you set None as default for the parameters? It will raise an exception at line 9 if any of the parameters is None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment