Main Content

Supported Video and Audio File Formats

Video and audio files in MATLAB®and their supported file formats and codecs.

Video Data inMATLAB

What Are Video Files?

For video data, the term “file format” often refers to either thecontainer formator thecodec. A container format describes the layout of the file, while a codec describes how to encode/decode the video data. Many container formats can hold data encoded with different codecs.

To read a video file, any application must:

  • Recognize the container format (such as AVI).

  • 获得的编解码器解码的视频吗data stored in the file. Some codecs are part of standard Windows®andMacintoshsystem installations, and allow you to play video inWindows Media®中国人民解放军yerorQuickTime. In MATLAB,VideoReadercan access most, but not all, of these codecs.

  • Properly use the codec to decode the video data in the file.VideoReadercannot always read files associated with codecs that were not part of your original system installation.

Formats ThatVideoReaderSupports

UseVideoReaderto read video files in MATLAB. The file formats thatVideoReadersupports vary by platform, and have no restrictions on file extensions.

中国人民解放军tforms

File Formats

All Platforms

AVI, including uncompressed, indexed, grayscale, and Motion JPEG-encoded video (.avi)
Motion JPEG 2000 (.mj2)

All Windows

MPEG-1 (.mpg)
Windows Media Video (.wmv,.asf,.asx)
微软支持的任何格式万博1manbetx®DirectShow®

Windows 7or later

MPEG-4, including H.264 encoded video (.mp4,.m4v)
AppleQuickTimeMovie (.mov)
微软支持的任何格式万博1manbetxMedia Foundation

Macintosh

Most formats supported byQuickTime中国人民解放军yer, including:
MPEG-1 (.mpg)
MPEG-4, including H.264 encoded video (.mp4,.m4v)
AppleQuickTimeMovie (.mov)
3GPP
3GPP2
AVCHD
DV

Note:For OS X Yosemite (Version 10.10) and later, MPEG-4/H.264 files written usingVideoWriter, play correctly, but display an inexact frame rate.

Linux®

Any format supported by your installed plug-ins for GStreamer 1.0 or higher, as listed onhttps://gstreamer.freedesktop.org/documentation/plugins_doc.html, including Ogg Theora (.ogg).

View Codec Associated with Video File

This example shows how to view the codec associated with a video file, using themmfileinfofunction.

Store information about the sample video file,shuttle.avi, in a structure array namedinfo. Theinfostructure contains the following fields:Filename,Path,Duration,AudioandVideo.

info = mmfileinfo('shuttle.avi');

Show the properties in the command window by displaying the fields of theinfostructure. For example, to view information under theVideofield, typeinfo.Video

info.Video
ans =struct with fields:Format: 'Motion JPEG' Height: 288 Width: 512

The file,shuttle.avi, uses the Motion JPEG codec.

Troubleshooting: Errors Reading Video File

You might be unable to read a video file if MATLAB cannot access the appropriate codec. 64-bit applications use 64-bit codec libraries, while 32-bit applications use 32-bit codec libraries. For example, when working with 64-bit MATLAB, you cannot read video files that require access to a 32-bit codec installed on your system. To read these files, try one of the following:

  • Install a 64-bit codec that supports this file format. Then, try reading the file using 64-bit MATLAB.

  • Re-encode the file into a different format with a 64-bit codec that is installed on your computer.

Sometimes,VideoReadercannot open a video file for reading on Windows platforms. This might occur if you have installed a third-party codec that overrides your system settings. Uninstall the codec and try opening the video file in MATLAB again.

Audio Data inMATLAB

What Are Audio Files?

The audio signal in a file represents a series ofsamplesthat capture the amplitude of the sound over time. Thesample rateis the number of discrete samples taken per second and given in hertz. The precision of the samples, measured by thebit depth(number of bits per sample), depends on the available audio hardware.

MATLAB audio functions read and store single-channel (mono) audio data in anm-by-1 column vector, and stereo data in anm-by-2 matrix. In either case,mis the number of samples. For stereo data, the first column contains the left channel, and the second column contains the right channel.

Typically, each sample is a double-precision value between -1 and 1. In some cases, particularly when the audio hardware does not support high bit depths, audio files store the values as 8-bit or 16-bit integers. The range of the sample values depends on the available number of bits. For example, samples stored asuint8values can range from 0 to 255 (28– 1). The MATLABsoundandsoundscfunctions support only single- or double-precision values between -1 and 1. Other audio functions support multiple data types, as indicated on the function reference pages.

Formats ThataudioreadSupports

Useaudioreadto read audio files in MATLAB. Theaudioreadfunction supports these file formats.

中国人民解放军tform Support File Format
All platforms AIFC (.aifc)
AIFF (.aiff,.aif)
AU (.au)
FLAC (.flac)
OGG (.ogg)
OPUS (.opus)
WAVE (.wav)
Windows 7(or later),Macintosh, and Linux MP3 (.mp3)
MPEG-4 AAC (.m4a,.mp4)

On Windows platforms prior to Windows 7,audioreaddoes not read WAVE files with MP3 encoded data.

On Windows 7 (or later) platforms,audioreadmight also read any files supported by Windows Media Foundation.

On Linux platforms,audioreadmight also read any files supported by GStreamer.

audioreadcan extract audio from MPEG-4 (.mp4,.m4v) video files onWindows 7or later,Macintosh, and Linux, and from Windows Media Video (.wmv) and AVI (.avi) files on Windows 7 (or later) and Linux platforms.

See Also

|||

Related Topics