Created
April 14, 2017 19:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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