diff --git a/README.en.md b/README.en.md index f47e380753f404bf436f41108b7dbcd8d438e062..ff0f542921ccc99e2213d1baaeb3095ff6792b93 100644 --- a/README.en.md +++ b/README.en.md @@ -25,9 +25,9 @@ This sample supports only video recording. It does not integrate the audio capab ### Preview -| Home page | App usage example | -|---------------------------------------------------------------|---------------------------------------------------------------| -| ![AVCodec_Index.png](screenshots/device/AVCodec_Index.en.png) | ![AVCodecSample.gif](screenshots/device/AVCodecSample.en.gif) | +| Home page | Record page | +|-------------------------------------------------------|-----------------------------------------------------| +| ![AVCodec_Index.png](screenshots/device/Index.en.png) | ![AVCodecSample.gif](screenshots/device/record.png) | ### How to Use diff --git a/README.md b/README.md index 37c9a0210352ec23f2ff45cbd59ed4ee2572ae94..ba20abb373af20cd4d15a6f1f21b6c8f8a2ef634 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # 基于AVCodec能力的视频编解码 ### 介绍 + 本实例基于AVCodec能力,实现了基于视频编解码的视频播放和录制的功能。通过调用Native侧的编码器,解码器,以及封装和解封装功能,完成从相机录制流到mp4文件的转换,以及对封装好的视频进行解封装,并解码送显。基于本示例可帮助应用开发需要编解码进行视频播放和录制的场景。 - 视频播放的主要流程是将视频文件通过解封装->解码->送显/播放。 - 视频录制的主要流程是相机采集->编码->封装成mp4文件。 ### 播放支持的原子能力规格 + | 媒体格式 | 封装格式 | 码流格式 | |------|:--------|:------------------------------------| | 视频 | mp4 | 视频码流:H.264/H.265, 音频码流:AudioVivid | @@ -22,11 +24,13 @@ 注意,本示例仅支持视频录制,未集成音频能力,播放的视频仅支持横屏录制视频。 ### 效果预览 -| 应用主界面 | 应用使用展示 | -|------------------------------------------------------------|------------------------------------------------------------| -| ![AVCodec_Index.png](screenshots/device/AVCodec_Index.png) | ![AVCodecSample.gif](screenshots/device/AVCodecSample.gif) | + +| 应用主界面 | 录像页面 | +|----------------------------------------------------|-----------------------------------------------------| +| ![AVCodec_Index.png](screenshots/device/Index.png) | ![AVCodecSample.gif](screenshots/device/record.png) | ### 使用说明 + 1. 弹出是否允许“AVCodecVideo”使用相机?点击“允许” #### 录制 @@ -108,13 +112,18 @@ ### 具体实现 #### *录制* + ##### UI层 + 1. 在UI层Index页面,用户点击“录制”后,会拉起半模态界面,用户确认保存录制文件到图库。录制结束后,文件会存放于图库。 -2. 选择好文件后,会用刚刚打开的fd,和用户预设的录制参数,掉起ArkTS的initNative,待初始化结束后,调用OH_NativeWindow_GetSurfaceId接口,得到NativeWindow的surfaceId,并把surfaceId回调回UI层。 +2. +选择好文件后,会用刚刚打开的fd,和用户预设的录制参数,掉起ArkTS的initNative,待初始化结束后,调用OH_NativeWindow_GetSurfaceId接口,得到NativeWindow的surfaceId,并把surfaceId回调回UI层。 3. UI层拿到编码器给的surfaceId后,调起页面路由,携带该surfaceId,跳转到Recorder页面; -4. 录制页面XComponent构建时,会调起.onLoad()方法,此方法首先会拿到XComponent的surfaceId,然后调起createDualChannelPreview(),此函数会建立一个相机生产,XComponent和编码器的surface消费的生产消费模型。 +4. 录制页面XComponent构建时,会调起.onLoad()方法,此方法首先会拿到XComponent的surfaceId,然后调起createDualChannelPreview() + ,此函数会建立一个相机生产,XComponent和编码器的surface消费的生产消费模型。 ##### Native层 + 1. 进入录制界面后,编码器启动,开始对UI层相机预览流进行编码。 2. 编码器每编码成功一帧,sample_callback.cpp的输出回调OnNewOutputBuffer()就会调起一次,此时用户会拿到AVCodec框架给出的OH_AVBuffer; 3. 在输出回调中,用户需手动把帧buffer、index存入输出队列中,并通知输出线程解锁; @@ -123,17 +132,24 @@ 6. 最后调用FreeOutputBuffer接口后,这一帧buffer释放回AVCodec框架,实现buffer轮转。 #### *播放* + ##### UI层 + 1. 在UI层Index页面,用户点击播放按钮后,触发点击事件,调起selectFile()函数,该函数会调起图库的选择文件模块,拿到用户选取文件的路径; -2. 用户选择文件成功后,调起play()函数,该函数会根据上一步获取到的路径,打开一个文件,并获取到该文件的大小,改变按钮状态为不可用,之后调起ArkTS层暴露给应用层的playNative()接口; +2. 用户选择文件成功后,调起play() + 函数,该函数会根据上一步获取到的路径,打开一个文件,并获取到该文件的大小,改变按钮状态为不可用,之后调起ArkTS层暴露给应用层的playNative() + 接口; 3. 根据playNative字段,调起PlayerNative::Play()函数,此处会注册播放结束的回调。 4. 播放结束时,Callback()中napi_call_function()接口调起,通知应用层,恢复按钮状态为可用。 ##### ArkTS层 -1. 在PlayerNative.cpp的Init()中调用PluginManager()中的Export()方法,注册OnSurfaceCreatedCB()回调,当屏幕上出现新的XComponent时,将其转换并赋给单例类PluginManager中的pluginWindow_; + +1. 在PlayerNative.cpp的Init()中调用PluginManager()中的Export()方法,注册OnSurfaceCreatedCB() + 回调,当屏幕上出现新的XComponent时,将其转换并赋给单例类PluginManager中的pluginWindow_; ##### Native层 -1. 具体实现原理: + +1. 具体实现原理: - 解码器Start后,解码器每拿到一帧,OnNeedInputBuffer就会被调起一次,AVCodec框架会给用户一个OH_AVBuffer。 - 在输入回调中,用户需手动把帧buffer、index存入输入队列中,并同时输入线程解锁。 - 在输入线程中,把上一步的帧信息储存为bufferInfo后,pop出队。 diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 index f869c0488ce6e97d09a002a4e4246f32769bfbdf..3cbeccd57dfd48c19516811ccd1b34c1403642b2 100644 --- a/entry/build-profile.json5 +++ b/entry/build-profile.json5 @@ -26,9 +26,6 @@ "targets": [ { "name": "default" - }, - { - "name": "ohosTest", } ] } \ No newline at end of file diff --git a/screenshots/device/AVCodecSample.en.gif b/screenshots/device/AVCodecSample.en.gif deleted file mode 100644 index d4374f9bd14b32e50ca732999b6432373cb48741..0000000000000000000000000000000000000000 Binary files a/screenshots/device/AVCodecSample.en.gif and /dev/null differ diff --git a/screenshots/device/AVCodecSample.gif b/screenshots/device/AVCodecSample.gif deleted file mode 100644 index 04e0f77b71a2c786ab86caf3d727a92ed13c0af4..0000000000000000000000000000000000000000 Binary files a/screenshots/device/AVCodecSample.gif and /dev/null differ diff --git a/screenshots/device/AVCodec_Index.en.png b/screenshots/device/AVCodec_Index.en.png deleted file mode 100644 index 4d04a4c8b6f0474107f745144473fe457ade61f3..0000000000000000000000000000000000000000 Binary files a/screenshots/device/AVCodec_Index.en.png and /dev/null differ diff --git a/screenshots/device/AVCodec_Index.png b/screenshots/device/AVCodec_Index.png deleted file mode 100644 index 2be1928bded5808dbda7f5d4e710bac60b6ce662..0000000000000000000000000000000000000000 Binary files a/screenshots/device/AVCodec_Index.png and /dev/null differ diff --git a/screenshots/device/Index.en.png b/screenshots/device/Index.en.png new file mode 100644 index 0000000000000000000000000000000000000000..408ae5b1e290261f7b1a4cd2afcd2318fbd70ff0 Binary files /dev/null and b/screenshots/device/Index.en.png differ diff --git a/screenshots/device/Index.png b/screenshots/device/Index.png new file mode 100644 index 0000000000000000000000000000000000000000..d527f13ad906e5a5a893ddbf2e9266f0d8b41c80 Binary files /dev/null and b/screenshots/device/Index.png differ diff --git a/screenshots/device/record.png b/screenshots/device/record.png new file mode 100644 index 0000000000000000000000000000000000000000..3a8b69cfffe006cb0b4a36903a86c6bff90cd314 Binary files /dev/null and b/screenshots/device/record.png differ