1 Star 0 Fork 5.3K

yczhang / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
audio-and-video-recording-development-guide.md 21.87 KB
一键复制 编辑 原始数据 按行查看 历史
wenjun 提交于 2020-09-08 10:08 . add OpenHarmony 1.0 baseline

Audio and Video Recording Development Guide

When to Use

Audio and video recording is used to record audio and video and encapsulate output files based on the configured encoding format, sampling rate, and bit rate.

Available APIs

The audio and video recording APIs are as follows. For details about the APIs, see the interface document.

Table 1 Audio and Video Recording APIs

API

Function

Description

Recorder

static Recorder *CreateRecorder()

Creates a Recorder instance.

Recorder

int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId)

Setting a Video Source for Recording

Recorder

int32_t SetVideoEncoder(int32_t sourceId, VideoCodecFormat encoder)

Sets the type of the video encoder for recording.

Recorder

int32_t SetVideoSize(int32_t sourceId, int32_t width, int32_t height)

Sets the width and height of the recorded video.

Recorder

int32_t SetVideoFrameRate(int32_t sourceId, int32_t frameRate)

Sets the frame rate of the video to be recorded.

Recorder

int32_t SetVideoEncodingBitRate(int32_t sourceId, int32_t rate)

Sets the encoding bit rate of the recorded video.

Recorder

int32_t SetCaptureRate(int32_t sourceId, double fps)

Sets the frame capture rate of video frames.

Recorder

std::shared_ptr<OHOS::Surface> GetSurface(int32_t sourceId);

Obtains the surface of the corresponding input source.

Recorder

int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId)

Set the audio source for recording.

Recorder

int32_t SetAudioEncoder(int32_t sourceId, AudioCodecFormat encoder)

Sets the type of the audio encoder for recording.

Recorder

int32_t SetAudioSampleRate(int32_t sourceId, int32_t rate)

Sets the audio sampling rate for recording.

Recorder

int32_t SetAudioChannels(int32_t sourceId, int32_t num)

Sets the number of audio channels to be recorded.

Recorder

int32_t SetAudioEncodingBitRate(int32_t sourceId, int32_t bitRate)

Sets the encoding bit rate of the recorded audio.

Recorder

int32_t SetMaxDuration(int32_t duration)

Sets the maximum duration of a recorded file.

Recorder

int32_t SetOutputFormat(OutputFormatType format)

Sets the output file format.

Recorder

int32_t SetOutputFile(int32_t fd)

Sets the FD of the output file.

Recorder

int32_t SetNextOutputFile(int32_t fd);

Sets the fd of the next output file.

Recorder

int32_t SetMaxFileSize(int64_t size)

Sets the maximum file size of a recording session.

Recorder

int32_t SetRecorderCallback(const std::shared_ptr<RecorderCallback> &callback)

Registers the recording listener callback function.

Recorder

int32_t Prepare()

Prepare for recording.

Recorder

int32_t Start()

Starts recording.

Recorder

int32_t Pause()

Pauses recording.

Recorder

int32_t Resume()

Resumes recording.

Recorder

int32_t Stop(bool block)

Stops recording.

Recorder

int32_t Reset();

Resets recording.

Recorder

int32_t Release()

Releasing Recording Resources

Recorder

int32_t SetFileSplitDuration(FileSplitType type, int64_t timestamp, uint32_t duration)

Setting Split Recording

Recorder

int32_t SetParameter(int32_t sourceId, const Format &format)

Sets the extended recording parameters.

Limitations and Constraints

None

How to Develop

  1. This API is used to create a Recorder instance.

    Recorder *recorder = Recorder::CreateRecorder();
  2. Sets Recorder parameters, including the audio and video source information, audio and video encoding format, sampling rate, bit rate, and video width and height.

    int32_t sampleRate = 48000; 
    int32_t channelCount = 1;
    AudioCodecFormat audioFormat = AAC_LC;
    AudioSourceType inputSource = AUDIO_MIC;
    int32_t audioEncodingBitRate = sampleRate;
    VideoSourceType source = VIDEO_SOURCE_SURFACE_ES;
    int32_t frameRate = 30;
    float fps = 30;
    int32_t rate = 4096;
    int32_t sourceId = 0;
    int32_t audioSourceId = 0;
    int32_t width = 1920;
    int32_t height = 1080;
    VideoCodecFormat encoder = H264;
    recorder->SetVideoSource(source, sourceId); // Set the video source and obtain the sourceId.
    recorder->SetVideoEncoder(sourceId, encoder); // Set the video encoding format.
    recorder->SetVideoSize(sourceId, width, height); // Set the video width and height.
    recorder->SetVideoFrameRate(sourceId, frameRate); // Set the video frame rate.
    recorder->SetVideoEncodingBitRate(sourceId, rate); //: Sets the video encoding bit rate.
    recorder->SetCaptureRate(sourceId, frameRate); //: Sets the frame capture rate of video frames.
    recorder->SetAudioSource(inputSource, audioSourceId); // Set the audio source and obtain audioSourceId.
    recorder->SetAudioEncoder(audioSourceId, audioFormat); // Set the audio encoding format.
    recorder->SetAudioSampleRate(audioSourceId, sampleRate); // Set the audio sampling rate.
    recorder->SetAudioChannels(audioSourceId, channelCount); // Set the number of audio channels.
    recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate); // Set the audio encoding bit rate.
  3. Prepare for the recording. The Recorder prepares for the recording.

    recorder->Prepare(); // Prepares for recording.
  4. The Recorder starts recording based on the configured audio and video sources.

    recorder->Start(); // Start recording.
  5. Stop recording and release resources.

    recorder->Stop(); // Stop recording.
    recorder->Release(); // Release recording resources.
1
https://gitee.com/myzyc/docs.git
git@gitee.com:myzyc/docs.git
myzyc
docs
docs
master

搜索帮助