OpenCV 4.12.0
开源计算机视觉
加载中...
搜索中...
无匹配项
cv::VideoWriter 类参考

视频写入器类。更多...

#include <opencv2/videoio.hpp>

cv::VideoWriter 的协作图

公共成员函数

 VideoWriter ()
 默认构造函数。
 
 VideoWriter (const String &filename, int apiPreference, int fourcc, double fps, const Size &frameSize, const std::vector< int > &params)
 
 VideoWriter (const String &filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor=true)
 
 VideoWriter (const String &filename, int fourcc, double fps, const Size &frameSize, const std::vector< int > &params)
 
 VideoWriter (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true)
 
virtual ~VideoWriter ()
 默认析构函数。
 
virtual double get (int propId) const
 返回指定的 VideoWriter 属性。
 
String getBackendName () const
 返回使用的后端API名称。
 
virtual bool isOpened () const
 如果视频写入器已成功初始化,则返回 true。
 
bool open (const String &filename, int apiPreference, int fourcc, double fps, const Size &frameSize, const std::vector< int > &params)
 
bool open (const String &filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor=true)
 
bool open (const String &filename, int fourcc, double fps, const Size &frameSize, const std::vector< int > &params)
 
virtual bool open (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true)
 初始化或重新初始化视频写入器。
 
virtual VideoWriteroperator<< (const Mat &image)
 用于写入下一视频帧的流运算符。
 
virtual VideoWriteroperator<< (const UMat &image)
 
virtual void release ()
 关闭视频写入器。
 
virtual bool set (int propId, double value)
 VideoWriter 中设置属性。
 
virtual void write (InputArray image)
 写入下一个视频帧。
 

静态公共成员函数

static int fourcc (char c1, char c2, char c3, char c4)
 将 4 个字符连接成一个 fourcc 代码。
 

静态保护成员函数

static Ptr< IVideoWriter > create (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true)
 

保护属性

Ptr< IVideoWriter > iwriter
 
Ptr< CvVideoWriterwriter
 

详细描述

视频写入类。

该类提供了用于写入视频文件或图像序列的 C++ API。

示例
samples/cpp/tutorial_code/videoio/video-write/video-write.cppsamples/cpp/videowriter_basic.cppsamples/tapi/hog.cpp

构造函数 & 析构函数文档

◆ VideoWriter() [1/5]

cv::VideoWriter::VideoWriter ( )
Python
cv.VideoWriter() -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize, params) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize, params) -> <VideoWriter object>

默认构造函数。

构造函数/函数初始化视频写入器。

  • 在 Linux 上,FFMPEG 用于写入视频;
  • 在 Windows 上,使用 FFMPEG 或 MSWF 或 DSHOW;
  • 在 MacOSX 上,使用 AVFoundation。

◆ VideoWriter() [2/5]

cv::VideoWriter::VideoWriter ( const String & filename,
int fourcc,
double fps,
Size frameSize,
bool isColor = true )
Python
cv.VideoWriter() -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize, params) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize, params) -> <VideoWriter object>

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。

参数
filename输出视频文件的名称。
fourcc用于压缩帧的编解码器的 4 字符代码。例如,VideoWriter::fourcc('P','I','M','1') 是 MPEG-1 编解码器,VideoWriter::fourcc('M','J','P','G') 是 motion-jpeg 编解码器等。代码列表可以在 MSDN 页面获取,或者在 fourcc 网站的这个 页面 获取更完整的列表。带有 MP4 容器的 FFMPEG 后端原生使用其他值作为 fourcc 代码:参见 ObjectType,因此您可能会收到 OpenCV 关于 fourcc 代码转换的警告消息。
fps创建的视频流的帧率。
frameSize视频帧的大小。
isColor如果它不为零,编码器将期望并编码彩色帧,否则它将处理灰度帧。

提示

  • 在某些后端中,fourcc=-1 会弹出系统中的编解码器选择对话框。
  • 要保存图像序列,请使用适当的文件名(例如 img_%02d.jpg)并设置 fourcc=0fps=0。使用未压缩的图像格式(例如 img_%02d.BMP)保存原始帧。
  • 大多数编解码器都是有损的。如果您想要无损视频文件,则需要使用无损编解码器(例如 FFMPEG FFV1、Huffman HFYU、Lagarith LAGS 等...)。
  • 如果启用了 FFMPEG,使用 codec=0; fps=0; 可以创建未压缩(原始)视频文件。
  • 如果使用 FFMPEG,我们允许奇数宽度或高度的帧,但在这种情况下,我们会截断最右边的列/最底部的一行。这可能应该更优雅地处理,但 FFMPEG swscale 内部的一些函数需要偶数宽度/高度。

◆ VideoWriter() [3/5]

cv::VideoWriter::VideoWriter ( const String & filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize,
bool isColor = true )
Python
cv.VideoWriter() -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize, params) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize, params) -> <VideoWriter object>

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。apiPreference 参数允许指定要使用的 API 后端。如果存在多个后端,可以用于强制使用特定的读取器实现:例如 cv::CAP_FFMPEGcv::CAP_GSTREAMER

◆ VideoWriter() [4/5]

cv::VideoWriter::VideoWriter ( const String & filename,
int fourcc,
double fps,
const Size & frameSize,
const std::vector< int > & params )
Python
cv.VideoWriter() -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize, params) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize, params) -> <VideoWriter object>

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。params 参数允许指定额外的编码器参数,编码为对(paramId_1, paramValue_1, paramId_2, paramValue_2, ... .)参见 cv::VideoWriterProperties

◆ VideoWriter() [5/5]

cv::VideoWriter::VideoWriter ( const String & filename,
int apiPreference,
int fourcc,
double fps,
const Size & frameSize,
const std::vector< int > & params )
Python
cv.VideoWriter() -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>
cv.VideoWriter(filename, fourcc, fps, frameSize, params) -> <VideoWriter object>
cv.VideoWriter(filename, apiPreference, fourcc, fps, frameSize, params) -> <VideoWriter object>

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。

◆ ~VideoWriter()

virtual cv::VideoWriter::~VideoWriter ( )
virtual

默认析构函数。

该方法首先调用 VideoWriter::release 关闭已打开的文件。

成员函数文档

◆ create()

static Ptr< IVideoWriter > cv::VideoWriter::create ( const String & filename,
int fourcc,
double fps,
Size frameSize,
bool isColor = true )
staticprotected

◆ fourcc()

static int cv::VideoWriter::fourcc ( char c1,
char c2,
char c3,
char c4 )
static
Python
cv.VideoWriter.fourcc(c1, c2, c3, c4) -> retval
cv.VideoWriter_fourcc(c1, c2, c3, c4) -> retval

将 4 个字符连接成一个 fourcc 代码。

返回
一个 fourcc 代码

此静态方法构造将在构造函数 VideoWriter::VideoWriterVideoWriter::open 中使用的编解码器的 fourcc 代码。

◆ get()

virtual double cv::VideoWriter::get ( int propId) const
virtual
Python
cv.VideoWriter.get(propId) -> retval

返回指定的 VideoWriter 属性。

参数
propId来自 cv::VideoWriterProperties 的属性标识符(例如 cv::VIDEOWRITER_PROP_QUALITY)或 视频 I/O API 后端的附加标志 之一
返回
指定属性的值。当查询 VideoWriter 实例使用的后端不支持的属性时,返回值为 0。

◆ getBackendName()

String cv::VideoWriter::getBackendName ( ) const
Python
cv.VideoWriter.getBackendName() -> retval

返回使用的后端API名称。

注意
流应已打开。

◆ isOpened()

virtual bool cv::VideoWriter::isOpened ( ) const
virtual
Python
cv.VideoWriter.isOpened() -> retval

如果视频写入器已成功初始化,则返回 true。

示例
samples/cpp/tutorial_code/videoio/video-write/video-write.cppsamples/cpp/videowriter_basic.cppsamples/tapi/hog.cpp

◆ open() [1/4]

bool cv::VideoWriter::open ( const String & filename,
int apiPreference,
int fourcc,
double fps,
const Size & frameSize,
const std::vector< int > & params )
Python
cv.VideoWriter.open(filename, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, fourcc, fps, frameSize, params) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize, params) -> retval

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。

◆ open() [2/4]

bool cv::VideoWriter::open ( const String & filename,
int apiPreference,
int fourcc,
double fps,
Size frameSize,
bool isColor = true )
Python
cv.VideoWriter.open(filename, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, fourcc, fps, frameSize, params) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize, params) -> retval

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。

◆ open() [3/4]

bool cv::VideoWriter::open ( const String & filename,
int fourcc,
double fps,
const Size & frameSize,
const std::vector< int > & params )
Python
cv.VideoWriter.open(filename, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, fourcc, fps, frameSize, params) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize, params) -> retval

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。

◆ open() [4/4]

virtual bool cv::VideoWriter::open ( const String & filename,
int fourcc,
double fps,
Size frameSize,
bool isColor = true )
virtual
Python
cv.VideoWriter.open(filename, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize[, isColor]) -> retval
cv.VideoWriter.open(filename, fourcc, fps, frameSize, params) -> retval
cv.VideoWriter.open(filename, apiPreference, fourcc, fps, frameSize, params) -> retval

初始化或重新初始化视频写入器。

该方法打开视频写入器。参数与构造函数 VideoWriter::VideoWriter 中的参数相同。

返回
如果视频写入器已成功初始化,则为 true

该方法首先调用 VideoWriter::release 关闭已打开的文件。

示例
samples/cpp/tutorial_code/videoio/video-write/video-write.cppsamples/cpp/videowriter_basic.cppsamples/tapi/hog.cpp

◆ operator<<() [1/2]

virtual VideoWriter & cv::VideoWriter::operator<< ( const Mat & image)
virtual

用于写入下一视频帧的流运算符。

另请参见

◆ operator<<() [2/2]

virtual VideoWriter & cv::VideoWriter::operator<< ( const UMat & image)
virtual

这是一个重载成员函数,为方便起见提供。它与上述函数的区别仅在于它接受的参数。

另请参见

◆ release()

virtual void cv::VideoWriter::release ( )
virtual
Python
cv.VideoWriter.release() ->

关闭视频写入器。

该方法由随后的 VideoWriter::openVideoWriter 析构函数自动调用。

◆ set()

virtual bool cv::VideoWriter::set ( int propId,
double  )
virtual
Python
cv.VideoWriter.set(propId, value) -> retval

VideoWriter 中设置属性。

参数
propId来自 cv::VideoWriterProperties 的属性标识符(例如 cv::VIDEOWRITER_PROP_QUALITY)或 视频 I/O API 后端的附加标志 之一
属性的值。
返回
如果该属性受 VideoWriter 实例使用的后端支持,则为 true

◆ write()

virtual void cv::VideoWriter::write ( InputArray image)
virtual
Python
cv.VideoWriter.write(image) ->

写入下一个视频帧。

参数
image写入的帧。通常,彩色图像应为 BGR 格式。

此函数/方法将指定的图像写入视频文件。它必须与打开视频写入器时指定的大小相同。

示例
samples/cpp/videowriter_basic.cpp.

成员数据文档

◆ iwriter

Ptr<IVideoWriter> cv::VideoWriter::iwriter
保护

◆ writer

Ptr<CvVideoWriter> cv::VideoWriter::writer
保护

该类的文档由以下文件生成