diff --git a/README.en.md b/README.en.md index cbd66b78e4f3b49b21e59aea25b9461018e25837..3360f78c3dc29d8ea857075ccc4ad7072e90c8fe 100644 --- a/README.en.md +++ b/README.en.md @@ -21,12 +21,11 @@ This sample demonstrates video playback and recording implemented on AVCodec. |---------------|------------------| | mp4 | H.264/H.265 | - ### Preview -| Home page | App usage example | -|---------------------------------------------------------------|---------------------------------------------------------------| -| ![AVCodec_Index.png](screenshots/device/AVCodec_Index.en.png) | ![AVCodecSample.gif](screenshots/device/AVCodecSample.en.gif) | +| Home page | App usage example | +|-------------------------------------------------------|-----------------------------------------------------| +| ![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 ee4a99737392928becd7e6df243b9afe3ccd6b26..033697a20f78515ab6b9d4882a456f6cdee66900 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # 基于AVCodec能力的视频编解码 ### 介绍 + 本实例基于AVCodec能力,实现了基于视频编解码的视频播放和录制的功能。通过调用Native侧的编码器,解码器,以及封装和解封装功能,完成从相机录制流到mp4文件的转换,以及对封装好的视频进行解封装,并解码送显。基于本示例可帮助应用开发需要编解码进行视频播放和录制的场景。 - 视频播放的主要流程是将视频文件通过解封装->解码->送显/播放。 - 视频录制的主要流程是相机采集->编码->封装成mp4文件。 ### 播放支持的原子能力规格 + | 媒体格式 | 封装格式 | 码流格式 | |------|:--------|:------------------------------------| | 视频 | mp4 | 视频码流:H.264/H.265, 音频码流:AudioVivid | @@ -19,13 +21,14 @@ |------|-------------| | mp4 | H.264/H.265 | - ### 效果预览 -| 应用主界面 | 应用使用展示 | -|------------------------------------------------------------|------------------------------------------------------------| -| ![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 +111,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 +131,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 e825ce51f0a99668d420bac3838dca0969e0c132..6e8afeb0fbff7c2a8ab30149bf0d44e42d872777 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 4612428d35328cb37b3f21ab25bc5337e8d854b3..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 b819db40469bdc097d14e5a93223627ce236d673..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 b0817c678a8cf1058f769a9d687f97eedb5aa485..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 a3cdf31d6a86c8b7dfa45d2a8970a24aa871817b..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