QtMultiMedia之CameraRecorder

QtMultiMedia 之 CameraRecorder

翻译: qyvlik

5.5.1

Camera 提供视频录制控制。

属性

  • actualLocation : string

  • audioBitRate : int

  • audioChannels : int

  • audioCodec : string

  • audioEncodingMode : enumeration

  • audioSampleRate : int

  • duration : int

  • errorCode : enumeration

  • errorString : string

  • frameRate : qreal

  • mediaContainer : string

  • muted : bool

  • outputLocation : string

  • recorderState : enumeration

  • recorderStatus : enumeration

  • resolution : size

  • videoBitRate : int

  • videoCodec : string

  • videoEncodingMode : enumeration

方法

  • record()

  • setMetadata(key, value)

  • stop()

详细描述

CameraRecorder allows recording camera streams to files, and adjusting recording settings and metadata for videos.

It should not be constructed separately, instead the videoRecorder property of a Camera should be used.

CameraRecorder 允许录制视频流到文件,为视频调整设置和元信息(例如 gps 等信息)。

CameraRecorder 不能直接创建,只能通过某个实例化的 CameravideoRecorder 属性来使用。

Camera {
    videoRecorder.audioEncodingMode: CameraRecorder.ConstantBitrateEncoding;
    videoRecorder.audioBitRate: 128000
    videoRecorder.mediaContainer: "mp4"
    // ...
}

There are many different settings for each part of the recording process (audio, video, and output formats), as well as control over muting and where to store the output file.

录制过程中有许多设置,例如音频,视频,输出格式等,也允许控制是否静音以及存储路径等。

属性文档

actualLocation : string

This property holds the actual location of the last saved media content. The actual location is usually available after the recording starts, and reset when new location is set or the new recording starts.

这个属性保存的是最后保存的媒体内容的本地路径。通常在录制开始后这个本地路径才有效,当开始新的录制时,这个本地路径就会更新。

audioBitRate : int

This property holds the audio bit rate (in bits per second) to be used for recording video.

这个属性设置了录制视频时音频的比特率。

audioChannels : int

This property indicates the number of audio channels to be encoded while recording video (1 is mono, 2 is stereo).

在录制视频时,这个属性表示音频的通道数。(1 是 单声道,2 是立体声)。

不过原文中单声道是 momo,momo 是什么鬼

audioCodec : string

This property holds the audio codec to be used for recording video. Typically this is aac or amr-wb.

录制视频时指定的音频格式,一般是 aac 或者 amr-wb

audioEncodingMode : enumeration

The type of encoding method to use when recording audio.

录制音频的编码模式。

ValueDescription
ConstantQualityEncodingEncoding will aim to have a constant quality, adjusting bitrate to fit. This is the default. The bitrate setting will be ignored.
ConstantBitRateEncodingEncoding will use a constant bit rate, adjust quality to fit. This is appropriate if you are trying to optimize for space.
AverageBitRateEncodingEncoding will try to keep an average bitrate setting, but will use more or less as needed.
描述
ConstantQualityEncoding编码时将有一个固定的质量,自动调整比特率。这个是默认值,自行设置比特率的将会被忽略。
ConstantBitRateEncoding编码时将有一个固定的比特率,自行设置质量值来调整。你可以适当的调整质量值来优化存储。
AverageBitRateEncoding编码时将会试图保存一个平均比特率,一般很少使用。

audioSampleRate : int

This property holds the sample rate to be used to encode audio while recording video.

录制视频时用来编码音频的采样率。

duration : int

This property holds the duration (in miliseconds) of the last recording.

最近一次录制的时长(毫秒)。

errorCode : enumeration

This property holds the last error code.

ValueDescription
NoErrorNo Errors
ResourceErrorDevice is not ready or not available.
FormatErrorCurrent format is not supported.
OutOfSpaceErrorNo space left on device.
描述
NoError没有错误
ResourceError设备还未就绪或者无法使用。
FormatError不支持当前格式。
OutOfSpaceError没有足够的存储空间。

errorString : string

This property holds the description of the last error.

保存最后一次错误描述。

frameRate : qreal

This property holds the framerate (in frames per second) to be used for recording video.

录制视频的帧率。

mediaContainer : string

This property holds the media container to be used for recording video. Typically this is mp4.

媒体容器,其实就是后缀名。默认为 mp4

muted : bool

This property indicates whether the audio input is muted during recording.

outputLocation : string

This property holds the destination location of the media content. If the location is empty, the recorder uses the system-specific place and file naming scheme.

媒体内容的终点路径(其实是保存路径?)。如果这个路径是空的,将会使用系统指定的路径和文件命名方式。

recorderState : enumeration

This property holds the current state of the camera recorder object.

相机的录制状态。

The state can be one of these two:

ValueDescription
StoppedStateThe camera is not recording video.
RecordingStateThe camera is recording video.

一般有两个状态:

ValueDescription
StoppedState没有录制。
RecordingState正在录制。

recorderStatus : enumeration

This property holds the current status of media recording.

录制媒体的状态。

ValueDescription
UnavailableStatusRecording is not supported by the camera.
UnloadedStatusThe recorder is available but not loaded.
LoadingStatusThe recorder is initializing.
LoadedStatusThe recorder is initialized and ready to record media.
StartingStatusRecording is requested but not active yet.
RecordingStatusRecording is active.
PausedStatusRecording is paused.
FinalizingStatusRecording is stopped with media being finalized.
ValueDescription
UnavailableStatus相机不支持录制。
UnloadedStatus相机支持录制,但是未加载。
LoadingStatus相机录制器正在初始化
LoadedStatus相机录制器完成初始化,可以开始录制。
StartingStatus相机录制器请求录制,等待响应中。
RecordingStatus相机录制器正在录制。
PausedStatus相机录制器暂停录制。
FinalizingStatus相机录制器停止录制。

resolution : size

This property holds the video frame dimensions to be used for video capture.

保存了视频帧的大小尺寸。

videoBitRate : int

This property holds the bit rate (in bits per second) to be used for recording video.

视频的比特率。

videoCodec : string

This property holds the video codec to be used for recording video. Typically this is h264.

视频的编码方式,默认 h264

videoEncodingMode : enumeration

This property holds the type of encoding method to be used for recording video.

录制视频的编码模式。

The following are the different encoding methods used:

ValueDescription
ConstantQualityEncodingEncoding will aim to have a constant quality, adjusting bitrate to fit. This is the default. The bitrate setting will be ignored.
ConstantBitRateEncodingEncoding will use a constant bit rate, adjust quality to fit. This is appropriate if you are trying to optimize for space.
AverageBitRateEncodingEncoding will try to keep an average bitrate setting, but will use more or less as needed.

有如下不同的模式可以使用:

描述
ConstantQualityEncoding编码时将有一个固定的质量,自动调整比特率。这个是默认值,自行设置比特率的将会被忽略。
ConstantBitRateEncoding编码时将有一个固定的比特率,自行设置质量值来调整。你可以适当的调整质量值来优化存储。
AverageBitRateEncoding编码时将会试图保存一个平均比特率,一般很少使用。

方法文档

record()

Starts recording.

开始录制。

setMetadata(key, value)

Sets metadata for the next video to be recorder, with the given key being associated with value.

为下一个视频设置元数据。

stop()

Stops recording.

停止录制。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt Camera是一个用于在Qt应用程序中访问和控制摄像头和视频录制功能的模块。使用Qt Camera模块,我们可以实现在应用程序中显示摄像头视频和录制视频的功能。 首先,我们需要使用QCamera类来访问摄像头设备。通过调用QCameraInfo::availableCameras()函数,可以获取到可用的摄像头设备列表。然后,我们可以选择一个摄像头设备来创建一个QCamera对象,如QCamera *camera = new QCamera(cameraDevices.at(0))。 接下来,我们可以使用QCameraViewfinder类来显示摄像头的视频。可以通过调用setCamera()函数将QCamera对象与QCameraViewfinder关联起来,并使用show()函数显示视频预览。例如,QCameraViewfinder *viewfinder = new QCameraViewfinder; viewfinder->setCamera(camera); viewfinder->show(); 同时,如果需要录制视频,我们可以使用QMediaRecorder类。通过调用setCamera()函数将QCamera对象与QMediaRecorder对象关联,并指定要保存视频的输出文件。然后,可以调用record()函数来开始录制视频,调用stop()函数来停止录制。例如,QMediaRecorder *recorder = new QMediaRecorder(camera); recorder->setOutputLocation(QUrl::fromLocalFile("path/to/save/video")); recorder->record(); 最后,我们需要在应用程序退出时释放资源。通过调用stop()函数停止摄像头和录制操作,并删除QCamera、QCameraViewfinder和QMediaRecorder对象。 综上所述,使用Qt Camera模块可以实现在应用程序中通过摄像头显示视频和录制视频的功能。通过适当的图形界面布局和用户交互设计,可以创建一个用户友好的视频录制应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值