How To Read Avi On Mac

In this post, we will learn how to read, write and display videos in OpenCV.

  1. Reading a Video. In OpenCV, a video can be read either by using the feed from a camera connected to a computer or by reading a video file. The first step towards reading a video file is to create a VideoCapture object. Its argument can be either the device index or the name of the video file to be read.
  2. I know AVI works not so well on Mac, so does MP4. Besides, we all know QT can’t support WMV or WMA. But don’t bothered. Without any plugins or codec, Macgo Blu-ray Player is just simple and easy Mac video player supporting all these files I mentioned here.
  3. AVI files must be converted to play on Mac. Download and install MPEG Streamclip from here: MPEG Streamclip drag the AVI file into MPEG Streamclip window and export to Quicktime H264.
  4. An AVI file uses less compression to store files and takes up more space than many other video formats—like MPEG and MOV. AVI files also can be created without the use of compression at all. This makes the files lossless, which results in immensely larger file sizes — approximately 2-3 GB per minute of video.

Before we do that, allow me a digression into a bit of history of video capture.

On June 15, 1898, in Palo Alto, California, a remarkable experiment was conducted to determine whether a galloping horse ever had all four feet off the ground at the same time. This historic experiment by photographer Eadweard Muybridge was the first time a motion sequence was captured in real time. It was financed by Leland Stanford of the Standford University fame.

Eadweard placed multiple cameras, 27 inches apart along the side of the race track. To every camera’s shutter was connected a thread that ran across the track. When the horse ran on the track, it broke one thread after the other triggering the camera shutters in series and exposing the films for one-thousandth of a second!

Browse the right AVI media file that you are trying to watch and then you can apply it to the video player in order to get started. Using this software will give you a high definition picture that.

This remarkable story almost did not happen. Just a few years before this achievement, Muybridge shot and killed his wife’s lover. The jury acquited him on grounds of “justifiable homicide!” But we have digressed a bit too far.

So, first up, what is a video? A video is a sequence of fast moving images. The obvious question that follows is how fast are the pictures moving? The measure of how fast the images are transitioning is given by a metric called frames per second(FPS). When someone says that the video has an FPS of 40, it means that 40 images are being displayed every second. Alternatively, after every 25 milliseconds, a new frame is displayed.

The other important attributes are the width and height of the frame.

Reading a Video

In OpenCV, a video can be read either by using the feed from a camera connected to a computer or by reading a video file. The first step towards reading a video file is to create a VideoCapture object. Its argument can be either the device index or the name of the video file to be read.

In most cases, only one camera is connected to the system. So, all we do is pass ‘0’ and OpenCV uses the only camera attached to the computer. When more than one camera is connected to the computer, we can select the second camera by passing ‘1’, the third camera by passing ‘2’ and so on.

Python

C++

After the VideoCapture object is created, we can capture the video frame by frame.

View Avi Video On Mac

Displaying a video

Play Avi Files On Mac

After reading a video file, we can display the video frame by frame. A frame of a video is simply an image and we display each frame the same way we display images, i.e., we use the function imshow().

As in the case of an image, we use the waitKey() after imshow() function to pause each frame in the video. In the case of an image, we pass ‘0’ to the waitKey() function, but for playing a video, we need to pass a number greater than ‘0’ to the waitKey() function. This is because ‘0’ would pause the frame in the video for an infinite amount of time and in a video we need each frame to be shown only for some finite interval of time, so we need to pass a number greater than ‘0’ to the waitKey() function. This number is equal to the time in milliseconds we want each frame to be displayed.

While reading the frames from a webcam, using waitKey(1) is appropriate because the display frame rate will be limited by the frame rate of the webcam even if we specify a delay of 1 ms in waitKey.

While reading frames from a video that you are processing, it may still be appropriate to set the time delay to 1 ms so that the thread is freed up to do the processing we want to do.

In rare cases, when the playback needs to be at a certain framerate, we may want the delay to be higher than 1 ms.

The Python and C++ implementation of reading and displaying a video file follows.

Python

C++

Writing a video

After we are done with capturing and processing the video frame by frame, the next step we would want to do is to save the video.

For images, it is straightforward. We just need to use cv2.imwrite(). But for videos, we need to toil a bit harder. We need to create a VideoWriter object. First, we should specify the output file name with its format (eg: output.avi). Then, we should specify the FourCC code and the number of frames per second (FPS). Lastly, the frame size should be passed.

Python

C++

FourCC is a 4-byte code used to specify the video codec. The list of available codes can be found at fourcc.org. There are many FOURCC codes available, but in this post, we will work only with MJPG.

Note: Only a few of the FourCC codes listed above will work on your system based on the availability of the codecs on your system. Sometimes, even when the specific codec is available, OpenCV may not be able to use it. MJPG is a safe choice.

The Python and C++ implementation of capturing live stream from a camera and writing it to a file follows.

Python

C++

Subscribe & Download Code

If you liked this article and would like to download code (C++ and Python) and example images used in this post, please subscribe to our newsletter. You will also receive a free Computer Vision Resource Guide. In our newsletter, we share OpenCV tutorials and examples written in C++/Python, and Computer Vision and Machine Learning algorithms and news.

3. QuickTime Won't Play AVI Files Problems and Solutions

I have a number of movie files that will not open and play with my Quicktime player even though they are .avi files...Should I download a file converter to change the AVI file format, say, mov. or download a codec to decode AVI files on MacBook.

How To Read Avi On Mac

This is because AVI codec, which is a bit complicated. Put it simply, you need to know how the AVI file is coded, and download the right codec to decode and reencode AVI video on Mac computer. Most AVI videos use Xvid, DivX and 3ivX codecs. It is a huge task to figure out codec your AVI files use and download the proper codec to open and watch AVI video on MacBook. If you are a person who struggle with technical things, this way is not recommended.

How To Read Avi Files On Mac

To realize a flawless AVI playback experience on your Macbook, you can install QuickTime component Perian. Perian helps QuickTime play AVI on MacBook, also other formats MKV, FLV, MTS, DivX, WMA and more. After being installed, Perian works automatically when playing AVI files with QT in MacBook. However, you need to note that QuickTime won’t play all media types, including AVI files with codecs unaccepted by QT. What's more, Perian is no longer under development and it fails to work with QuickTime 10 or later. So, we suggest you to convert AVI to MP4, MOV QuickTime supported formats.

How To Read Avi Files

Author: Candice Liu Updated on May 25, 2020