How to play .avi file in Google Colab?

Viewed 4064

I have found only ways to play '.mp4' files. I even tried to download .avi file and it is showing file is corrupted. I even tried to change .avi to .mp4 using online tools but nothing worked fine.

2 Answers

Use the python moviepy package

from moviepy.editor import *

path="file.avi" 

clip=VideoFileClip(path)
clip.ipython_display(width=280)

You need to convert avi to mp4 with ffmepg

!ffmpeg -i input.avi output.mp4

Then get the file content into data_url

from IPython.display import HTML
from base64 import b64encode
mp4 = open('output.mp4','rb').read()
data_url = "data:video/mp4;base64," + b64encode(mp4).decode()

Then display it with HTML()

HTML("""
<video controls>
      <source src="%s" type="video/mp4">
</video>
""" % data_url)

Here's a working example.

Related