Importing & Exporting Video
The Wolfram Language supports importing from and exporting to a large number of multimedia containers and codecs. Together with the complete stacks for image and audio processing, this opens up video processing from simple processing to highly sophisticated analysis.
A video file can be imported into the Wolfram Language as a Video object for further processing and analysis. Different parts of the data or metadata stored in video files are directly accessible via import elements.
Import["file"] | import video files as a Video object |
Import["file",elem] |
import video frames, audio, etc. from a video file
|
Import["http://…"] | import a remote video as a Video object |
Import a video file as a Video object:
Supported video formats include "AVI", "Matroska", "MP4", "Ogg" and "QuickTime". Import also tries to import other video files using the catch-all format "VideoFormat".
Each media container can store data using several different encodings. Codec support varies from one platform to another.
$VideoDecoders | supported video decoders |
$AudioDecoders | supported audio decoders |
$SubtitleDecoders | supported subtitle decoders |
Video objects, animations or lists of image frames can be exported to video files with or without audio data.
Export["file.ext",video] | export a Video object to a video file |
Export["file.ext",images] | export a list of images to a video file |
Export["file.ext",rules,"Rules"] | export video with audio to a video file |
Animations and lists of frames can be combined with Audio objects when exported to a video file.
Supported video formats are "AVI", "Matroska", "MP4", "Ogg" and "QuickTime". Each media container can store data using several different encodings. The support for codecs varies from one platform to another.
Supported video containers in Export:
$VideoEncoders | supported video encoders |
$AudioEncoders | supported audio encoders |
$SubtitleEncoders | supported subtitle encoders |
The Wolfram Language by default uses the operating system as well as a limited version of FFmpeg for decoding and encoding video files.
Install FFmpeg Version 4.0.0 or higher to get a more complete codec support. See the following for platform-specific instructions.
Installing FFmpeg
Only 64-bit shared (not static) builds of FFmpeg 4.0.0 or later are supported on Windows, macOS and Linux.
On Windows, download shared binaries from http://ffmpeg.org, install, and add the directory containing ffmpeg.exe and the dynamic libraries (such as av*.dll files) to the PATH environment variable.
On macOS, install using Homebrew or MacPorts in either of the following locations: /usr/local/lib, /opt/homebrew/lib or /opt/local/lib.
Alternatively, download FFmpeg sources from http://ffmpeg.org and build with shared linking; enable GPL parts and all necessary codecs.