Audio/Video Recording Development
When to Use
To record audios and videos, use APIs described in this section to set the encoding format, sampling rate, and bit rate, and encapsulate output files based on the parameters.
Available APIs
The following table describes APIs available for audio and video recording.
Table 1 APIs available for media recording
Limitations and Constraints
None
How to Develop
-
Create a Recorder instance.
Recorder *recorder = new Recorder();
-
Sets parameters for the Recorder instance, including the media source information, 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; double 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 source ID. 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); // Set the video encoding bit rate. recorder->SetCaptureRate(sourceId, fps); // Set the capture rate for video frames. recorder->SetAudioSource(inputSource, audioSourceId); // Set the audio source and obtain the source ID. 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.
-
Prepare the Recorder instance for recording.
recorder->Prepare(); // Prepare for recording.
-
Start recording. The Recorder instance starts recording based on the audio and video sources.
recorder->Start(); // Start recording.
-
Stop recording and release resources.
recorder->Stop(); // Stop recording. recorder->Release(); // Release recording resources.