main Content

Vision.VideofileWriter

Write video frames and audio samples to video file

Description

视频FileWriterOBJect writes video frames and audio samples to a video file. The video and audio can be compressed. The available compression types depend on the encoders installed on the platform.

笔记

This block supports code generation for platforms that have file I/O available. You cannot use this block with金宝app®桌面实时™software, because that product does not support file I/O.

This object performs best on platforms with Version 11 or later of Windows Media®Player software. This object supports only uncompressed RGB24 AVI files on Linux®and苹果电脑platforms.

此对象的生成代码依赖于预先构建的库文件。您可以在MATLAB之外运行此代码®environment, or redeploy it, but be sure to account for these extra library files when doing so. The packNGo function creates a single zip file containing all of the pieces required to run or rebuild this code. SeepackNGo((Simulink Coder)为了more information.

要运行从对象生成的可执行文件,您可能需要将预编译的共享库文件添加到系统路径。看mATLAB CoderandSimulink Shared Library Dependencies有关详细信息。

笔记

从R2016b开始,而不是使用stepmethod to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example,y = step(obj,x)andy = obj(x)perform equivalent operations.

creation

Description

例子

VIDEOFWRITER = VISION.VIDEOFILEWRITERreturns a video file writer System object,videoFWriter。它将视频帧写入未压缩的output.avi'视频文件。每个电话step方法写一个视频框架。

videofwriter = vision.videofilewriter(Filenamereturns a video file writer object,videoFWriterthat writes video to a file,Filename。这file type can be。avi,,,,。mj2,,,,.mp4, 和.m4vspecified by theFileFormat财产。

videofwriter = vision.videofilewriter(___,,,,名称,价值configures the video file writer properties, specified as one or more name-value pair arguments. Unspecified properties have default values.

nameis a property name andValueis the corresponding value.namemust appear inside single quotes ('')。您可以指定几个name-value pair arguments in any order asname1,Value1,...,NameN,ValueN

Example:videofwriter = vision.videofilewriter('myfile.avi',,,,'帧,,,,。。。videoFReader.info.VideoFrameRate);

Properties

expand all

视频输出文件名,,,,specified as a character vector. The file extension you give forFilename必须匹配FileFormat

输出文件格式,,,,specified as one of the supported file formats shown in the table.

文件格式 Description 文件扩展名 Supported Platform

'AVI'

声音的-Video Interleave file 。avi 所有平台

'MJ2000'

motion JPEG 2000 file 。mj2 所有平台

'MPEG4'

MPEG-4/H.264视频 .mp4,,,,.m4v Windows®and苹果电脑

Write audio data, specified as错误的ortrue。利用this property to control whether the object writes audio samples to the video file. Set this value totrue写音频数据。要将音频和视频写入文件,您必须使用。avi为了mat .

视频帧率在帧每秒,指定一个s a positive numeric scalar. For videos which also contain audio data, the rate of the audio data will be determined as the rate of the video multiplied by the number of audio samples passed in. For example, if you use a frame rate of30,并通过1470个音频样本,对象将音频样本设置为44100((((1470 x 30 = 44100)。

指定用于实现音频数据的压缩算法的类型。此压缩减少了视频文件的大小。选择none (uncompressed)将未压缩的音频数据保存到视频文件中。其他选项反映了系统上安装的可用音频压缩算法。此属性仅在写作时适用AVIfiles on Windows platforms.

指定用于压缩视频数据的压缩算法的类型。此压缩减少了视频文件的大小。选择none (uncompressed)to save uncompressed video data to the video file. The视频压缩器property can also be set to one of the compressors available on your system. To obtain a list of available video compressors, you can use tab completion. Follow these steps:

  1. 实例化对象:

    y = vision.VideoFileWriter

  2. To launch the tab completion functionality, type the following up to the open quote.

    y.VideoCompressor='

    A list of compressors available on your system will appear after you press theTabkey. For example:

此属性仅在写作时适用AVIfiles on Windows platforms.

指定压缩输出音频数据类型。此属性仅在您编写未压缩时适用WAV文件。

Color space for output AVI file, specified asRGBoryCBcr4:2:2。This property applies when you set theFileFormat财产为AVIand only on Windows platforms.

输出视频文件的控制大小,在该范围内指定为整数[0,,,,100]。增加此值以提高视频质量。但是,这样做会增加文件大小。将值降低到较小的文件大小以降低视频质量。

Qualityproperty only applies when you are writing MPEG4 video files (on Windows or苹果电脑)or when you are writing MJPEG-AVI video only files on a Mac or Linux.

Target ratio between number of bytes in input image and compressed image, specified as an integer greater than1。这CompressionFactorindicates the target ratio between the number of bytes in the input image and the compressed image. The data is compressed as much as possible, up to the specified target. This property applies only when writing Lossy MJ2000 files.

用法

Description

例子

Filename= videoFWriter(videoFrame写一个视频框架,videoFrame,,,,to the output file. The input video can be anm-by-n-by-3 TrueColor RGB视频框架或m-by-ngrayscale video frame..

Filename= videoFWriter(videoFrame,,,,audio写入输入视频的一帧,videoFrame, 和one frame of audio samples,audio,,,,to the output file. This applies when you set the声音的InputPort财产为true

Filename= videoFWriter(videoFrame,,,,y,,,,CB,,,,cr,,,,audio写YCBCR的一帧4:2:2视频和一个音频样本框架,audio,,,,to the output file. This applies when you set the声音的InputPorttotrueand thefilecolorspace财产yCBcr4:2:2'。CB和CR颜色成分的宽度必须是Y宽度的一半。

输入参数

expand all

视频框架,,,,returned as a truecolor or 2-D grayscale image.

yCBcrcolor format, returned in theyCBcr4:2:2格式。

One frame of audio samples, returned in one of the following formats.

Platform Supported File Name Extensions
所有平台 AVI (。avi
Windows 图片
.jpg,,,,。bmp
视频
mpeg(。mpeg
mPEG-2 (.mp2
mPEG-1.mpg

mPEG-4, including H.264 encoded video (.mp4,。m4v
Motion JPEG 2000(。mj2
Windows Media Video (.wmv,,,,。asf,,,,。asx,。asx)
and any format supported by Microsoft DirectShow® 9.0 or higher.
声音的
海浪 (。wav
Windows Media Audio File (.wma
音频互换文件格式(。aif,,,,。aiff
Compressed Audio Interchange File Format(。aifc),
mP3 (.mp3
太阳音频(.au
苹果((。snd
苹果电脑intosh 视频
。avi
Motion JPEG 2000(。mj2
mPEG-4, including H.264 encoded video (.mp4,。m4v
苹果Quicktime电影(.mov)
and any format supported by QuickTime as listed on http://support.apple.com/kb/HT3775.
声音的
未压缩。avi
Linux Motion JPEG 2000(。mj2
Any format supported by your installed plug-ins for GStreamer 0.1 or higher, as listed on http://gstreamer.freedesktop.org/documentation/plugins.html, including Ogg Theora (.ogg).

Windows XPandWindows 7x64 platform ships with a limited set of 64-bit video and audio codecs. If a compressed multimedia file fails to play, try saving the multimedia file to a supported file format listed in the table above.

如果使用Windows,请使用Windows Media Player版本11或更高版本。

笔记

位深度高于8位的MJ2文件不支持金宝appvision.VideoFileReader。利用视频ReaderandVideOwriter为了higher bit depths.

Reading audio from compressed MP4 files with video and audio is not supported byvision.VideoFileReader

Output Arguments

expand all

视频输出文件名,,,,specified as'.avi',,,,'.mj2',,,,'。mp4', 和'。m4v'。您提供的文件扩展名Filename必须匹配FileFormat

对象功能

要使用对象函数,请将系统对象指定为第一个输入参数。例如,释放名称的系统对象的系统资源OBJ,,,,use this syntax:

释放(OBJ)

expand all

信息 Information about specified video file
isDone End-of-file status (logical)
step RunSystem object算法
发布 释放资源并允许更改System object属性值和输入特征
reset Reset internal states ofSystem object

Examples

全部收缩

Load a video file and write the file to a writer object.

videofreader = vision.videofilereader('viplanedeparture.mp4'); videoFWriter = vision.VideoFileWriter('myfile.avi',,,,。。。'帧,,,,videoFReader.info.VideoFrameRate);

Write the first 50 frames from original file into a newly createdmyFile.avifile.

为了i = 1:50 videoframe = videofReader();videofwriter(videoframe);结尾

Close the input and output files.

释放(videofreader);释放(videofwriter);

Extended Capabilities

版本历史记录

在R2012a中引入