2

How to play an .mp4 or .avi video in Google Colab?

I tried using the following code:

    from IPython.display import HTML
    from base64 import b64encode
    mp4 = open('video.mp4','rb').read()
    data_url = "data:video/mp4;base64," + b64encode(mp4).decode()
    HTML("""
    <video width=400 controls>
          <source src="%s" type="video/mp4">
    </video>
    """ % data_url)

Don't know why after executing this, the video doesn't play.There is no network issue in my place. Please help. Also, Is there any other way by which i can play .mp4 or avi video in Colab?

screenshot of code in colab notebook and the received output

Thank You

Developer
  • 21
  • 6
  • you can try OpenCV - https://stackoverflow.com/questions/58924926/cv2-imshow-doesnt-render-video-file-in-google-colab. Also make sure to copy it to the current directory – Lyman Zerga Mar 18 '20 at 21:17

0 Answers0