From 4566c7747030626cad9297686638689e1682039c Mon Sep 17 00:00:00 2001 From: shuboxu Date: Fri, 25 Aug 2023 02:33:13 +0000 Subject: [PATCH] update en/application-dev/media/video-recording.md. Signed-off-by: shuboxu --- en/application-dev/media/video-recording.md | 69 +++++++++++++-------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/en/application-dev/media/video-recording.md b/en/application-dev/media/video-recording.md index 11f795b526..3e3ab2163a 100644 --- a/en/application-dev/media/video-recording.md +++ b/en/application-dev/media/video-recording.md @@ -24,11 +24,11 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re ```ts import media from '@ohos.multimedia.media' - let avRecorder - media.createAVRecorder().then((recorder) => { - avRecorder = recorder - }, (error) => { - console.error('createAVRecorder failed') + let avRecorder: media.AVRecorder; + media.createAVRecorder().then((recorder: media.AVRecorder) => { + avRecorder = recorder + }, (error: Error) => { + console.error('createAVRecorder failed') }) ``` @@ -40,12 +40,12 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re ```ts // Callback function for state changes. - avRecorder.on('stateChange', (state, reason) => { - console.info('current state is: ' + state); + avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => { + console.info('current state is: ' + state); }) // Callback function for errors. - avRecorder.on('error', (err) => { - console.error('error happened, error message is ' + err); + avRecorder.on('error', (err: BusinessError) => { + console.error('error happened, error message is ' + err); }) ``` @@ -62,24 +62,41 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re > - The recording output URL (URL in **avConfig** in the sample code) must be in the format of fd://xx (where xx indicates a file descriptor). You must call [ohos.file.fs](../reference/apis/js-apis-file-fs.md) to implement access to the application file. For details, see [Application File Access and Management](../file-management/app-file-access.md). ```ts - let avProfile = { - fileFormat: media.ContainerFormatType.CFT_MPEG_4, // Video file encapsulation format. Only MP4 is supported. - videoBitrate: 200000, // Video bit rate. - videoCodec: media.CodecMimeType.VIDEO_AVC, // Video file encoding format. Both MPEG-4 and AVC are supported. - videoFrameWidth: 640, // Video frame width. - videoFrameHeight: 480, // Video frame height. - videoFrameRate: 30 // Video frame rate. + class AVProfile { + fileFormat: media.ContainerFormatType; + videoBitrate: number; + videoCodec: media.CodecMimeType; + videoFrameWidth: number; + videoFrameHeight: number; + videoFrameRate: number; } - let avConfig = { - videoSourceType: media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, // Video source type. YUV and ES are supported. - profile : this.avProfile, - url: 'fd://35', // Create, read, and write a file by referring to the sample code in Application File Access and Management. - rotation: 0, // Video rotation angle. The default value is 0, indicating that the video is not rotated. The value can be 0, 90, 180, or 270. + + class AVConfig { + videoSourceType: media.VideoSourceType; + profile: AVProfile; + url: string; + rotation: number; + } + + let avProfile: AVProfile = { + fileFormat: media.ContainerFormatType.CFT_MPEG_4, // Video file encapsulation format. Only MP4 is supported. + videoBitrate : 100000, // Video bit rate. + videoCodec: media.CodecMimeType.VIDEO_AVC, // Video file encoding format. Both MPEG-4 and AVC are supported. + videoFrameWidth: 640, // Video frame width. + videoFrameHeight: 480, // Video frame height. + videoFrameRate: 30 // Video frame rate. } + let avConfig: AVConfig = { + videoSourceType: media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, // Video source type. YUV and ES are supported. + profile : avProfile, + url: 'fd://35', // Create, read, and write a file by referring to the sample code in Application File Access and Management. + rotation: 0, // Video rotation angle. The default value is 0, indicating that the video is not rotated. The value can be 0, 90, 180, or 270. + } + avRecorder.prepare(avConfig).then(() => { - console.info('avRecorder prepare success') - }, (error) => { - console.error('avRecorder prepare failed') + console.info('avRecorder prepare success') + }, (error: Error) => { + console.error('avRecorder prepare failed') }) ``` @@ -90,9 +107,9 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re The video data collection module obtains the surface based on the surface ID and transmits video data to the AVRecorder through the surface. Then the AVRecorder processes the video data. ```ts - avRecorder.getInputSurface().then((surfaceId) => { + avRecorder.getInputSurface().then((surfaceId: string) => { console.info('avRecorder getInputSurface success') - }, (error) => { + }, (error: Error) => { console.error('avRecorder getInputSurface failed') }) ``` -- GitLab