Initializes or reinitializes video writer
successFlag = vid.open(filename, frameSize)
successFlag = vid.open(filename, frameSize, 'OptionName',optionValue, ...)
Input
- filename Name of the output video file
- frameSize Size of the video frames
[width, height]
.
Output
- successFlag bool, true if video writer has been
successfully initialized.
Options
- API The parameter allows to specify API backends to use.
Can be used to enforce a specific writer implementation if
multiple are available: e.g. 'FFMPEG' or 'GStreamer'
- Any (default) Auto detect
- VfW Video For Windows
- QuickTime QuickTime
- AVFoundation AVFoundation framework for iOS
- MediaFoundation Microsoft Media Foundation
- GStreamer GStreamer
- FFMPEG FFMPEG library
- Images OpenCV Image Sequence (e.g.
img_%02d.jpg
)
- MotionJPEG Built-in OpenCV MotionJPEG codec
- MediaSDK Intel Media SDK
- FourCC 4-character code of codec used to compress the
frames. List of codes can be obtained at [FOURCC]. FFMPEG
backend with MP4 container natively uses other values as
FourCC code: see [ObjectType], so you may receive a warning
message from OpenCV about fourcc code conversion. Examples are:
- PIM1 MPEG-1 codec
- MJPG Motion-JPEG codec (default)
- MP42 MPEG-4 (Microsoft)
- DIV3 DivX MPEG-4 Part 2
- DIVX DivX codec
- XVID XVID MPEG-4 Part 2
- U263 H263
- I263 ITU H.263
- FLV1 Sorenson Spark (Flash Video)
- X264 H.264
- AVC1 MPEG-4 Part 10/H.264 (Apple)
- WMV1 Windows Media Video 7 (Microsoft)
- WMV2 Windows Media Video 8 (Microsoft)
- -1 prompts with codec selection dialog (Windows only)
- FPS Framerate of the created video stream. default 25.
- Color If true, the encoder will expect and encode color
frames, otherwise it will work with grayscale frames (the flag
is currently supported on Windows only). default true
The method first calls cv.VideoWriter.release to close the
already opened file.
The method opens a video writer:
- On Linux FFMPEG is used to write videos;
- On Windows FFMPEG or VFW is used;
- On MacOSX QTKit is used.
Tips
- With some backends
FourCC=-1
pops up the codec selection
dialog from the system.
- To save image sequence use a proper filename (eg.
img_%02d.jpg
) and FourCC=0
OR FPS=0
. Use uncompressed
image format (eg. img_%02d.BMP
) to save raw frames.
- Most codecs are lossy. If you want lossless video file you
need to use a lossless codecs (eg. FFMPEG FFV1, Huffman HFYU,
Lagarith LAGS, etc...)
- If FFMPEG is enabled, using
codec=0; fps=0;
you can create
an uncompressed (raw) video file.
References
[FOURCC]:
Video Codecs by FOURCC
[ObjectType]:
Codecs