2 Star 4 Fork 0

Fu / trinity

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

trinity

icon~

Android Arsenal Build Status Download platform License

trinity是一个开源的拍摄和短视频处理工具,用kotlin和c++编写,实现了大部分短视频编辑软件热门功能。

Apk 下载

  • 请在Actions中每次commit ci编译的结果中下载

演示

QQ交流群

125218305

联系我

git commit 规范

代码规范

系统版本

支持Android 4.3及以上版本

开发环境

  • Android Studio 3.5
  • NDK r20
  • kotlin 1.3.41

使用的开源库

  • fdk-aac
  • ffmpeg 3.4
  • libx264
  • xlogger
  • mnnkit

功能

视频拍摄
功能说明 是否支持
多段录制
自定义时长
自定义相机配置
摄像头切换
闪光灯
焦距调节
手动对焦
静音
美颜 x
磨皮
自定义分辨率及码率
录制背景音
录制变速
软硬编码
视频编辑
多段编辑
替换片段
设置片段时间
背景音乐
硬解码
软解码
图片视频混合
特效
滤镜
闪白
两分屏
三分屏
四分屏
六分屏
九分屏
模糊分屏
高斯模糊
灵魂出窍
抖动
毛刺
70s
倒计时
爱心光斑
人脸识别
玫瑰眼妆
王妃
贴纸妆
飘落小猪
猫头

人脸特效

玫瑰眼妆

特效调试

项目中使用xcode调试特效效果, 使用前需要安装glfw

brew install glfw

然后使用xcode打开library/src/main/cpp/opengl.xcodeproj即可
切换效果调用代码

image_process.OnAction("param/blurScreen", 0);

自动化测试

  • 自动化测试使用uiautomator2具体使用请参考文档 使用方式如下:
cd trinity
python trinity.py

然后使用

adb devices

在终端输入设备名即可

性能

性能

使用

注意: SDK中不做权限判断,使用时需要由调用方申请好权限, SDK中涉及到的时间均为毫秒

添加jcenter依赖

dependencies {
    implementation 'com.github.wlanjie:trinity:0.2.9.1'
}

权限要求

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

录制

配置参数

  • 创建录制预览view
val preview = findViewById<TrinityPreviewView>(R.id.preview)
  • 创建录制接口实例
mRecord = TrinityRecord(preview)
  • 销毁录制接口实例
mRecord.release()

回调设置

  • 设置视频渲染回调
mRecord.setOnRenderListener(this)
  • 设置录制进度回调
mRecord.setOnRecordingListener(this)
  • 设置相机回调
mRecord.setCameraCallback(this)

开启预览

  • 开始预览
mRecord.startPreview()
  • 结束预览
mRecord.stopPreview()
  • 设置预览类型
// 设置显示类型
// 包含裁剪显示, 原比例上下留黑显示
mRecord.setFrame(mFrame)

录制控制/管理

  • 切换摄像头
mRecord.switchCamera()
  • 获取当前摄像头
// 返回当前摄像头id
val facing = mRecord.getCameraFacing()
  • 开关闪光灯
mRecord.flash(mFlash)
  • 设置zoom
// 设置焦距缩放, 0-100 100为最大缩放
mRecord.setZoom(0)
  • 设置曝光度
// 设置相机曝光度, 100为最大曝光
mRecord.setExposureCompensation(0)
  • 手动对焦
// 设置手动对焦, 参数为x和y
mRecord.focus(mPointF)
  • 设置录制视频的角度
/**
 * @param rotation 旋转角度包含 0 90 180 270
 */
mRecord.setRecordRotation(0)
  • 设置静音录制
mRecord.setMute(false)
  • 倍速录制
/**
 * @param speed 速度包含 0.25 0.5 1.0 2.0 4.0倍速
 */
mRecord.setSpeed(mSpeed)

开始录制

  • 开始录制一段视频
/**
 * 开始录制一段视频
 * @param path 录制的视频保存的地址
 * @param width 录制视频的宽, SDK中会做16倍整数的运算, 可能最终输出视频的宽和设置进去的不一致
 * @param height 录制视频的高, SDK中会做16倍整数的运算, 可能最终输出视频的宽和设置进去的不一致
 * @param videoBitRate 视频输出的码率, 如果设置的是2000, 则为2M, 最终输出的和设置的可能有差别
 * @param frameRate 视频输出的帧率
 * @param useHardWareEncode 是否使用硬编码, 如果设置为true, 而硬编码不支持,则自动切换到软编码
 * @param audioSampleRate 音频的采样率
 * @param audioChannel 音频的声道数
 * @param audioBitRate 音频的码率
 * @param duration 需要录制多少时间
 * @return Int ErrorCode.SUCCESS 为成功,其它为失败
 * @throws InitRecorderFailException
 */
mRecord.startRecording("/sdcard/a.mp4",
                      720,
                      1280,
                      2000, // 2M码率
                      30,
                      false,
                      44100,
                      1, // 单声道
                      128, // 128K 码率
                      Int.MAX_VALUE)
  • 结束录制
mRecord.stopRecording()

视频编辑

初始化

  • 创建编辑器实例
mVideoEditor = TrinityCore.createEditor(this)
  • 设置预览画面
val surfaceView = findViewById<SurfaceView>(R.id.surface_view)
mVideoEditor.setSurfaceView(surfaceView)

导入视频

  • 添加一个片段
val clip = MediaClip(file.absolutePath)
mVideoEditor.insertClip(clip)
  • 根据下标添加片段
val clip = MediaClip(file.absolutePath)
mVideoEditor.insertClip(0, clip)
  • 删除一个片段
/**
 * 根据下标删除一个片段
 */
mVideoEditor.removeClip(index)
  • 获取片段的数量
val count = mVideoEditor.getClipsCount()
  • 根据下标获取一个片段
/**
 * 如果片段不存在, 返回一个null
 */
val clip = mVideoEditor.getClip(index)
  • 根据下标替换一个片段
mVideoEditor.replaceClip(index, clip)
  • 获取所有片段
/**
 * 返回所有片段的集合
 */
val clips = mVideoEditor.getVideoClips()
  • 获取所有片段的时间总长
val duration = mVideoEditor.getVideoDuration()
  • 获取当前播放片段的进度
val current = mVideoEditor.getCurrentPosition()
  • 获取指定片段的开始和结束时间
val timeRange = mVideoEditor.getClipTimeRange(index)
  • 根据时间查找片段的下标
val index = mVideoEditor.getClipIndex(time)

背景音乐

  • 添加背景音乐
/**
 * @param config 背景音乐json内容
 * 具体json内容如下:
 * {
 *    "path": "/sdcard/trinity.mp3",
 *    "startTime": 0,
 *    "endTime": 2000
 * }
 * json 参数解释:
 * path: 音乐的本地地址
 * startTime: 这个音乐的开始时间
 * endTime: 这个音乐的结束时间 2000代表这个音乐只播放2秒钟
 */
val actionId = mVideoEditor.addMusic(config)
  • 更新背景音乐
/**
 * @param config 背景音乐json内容
 * 具体json内容如下:
 * {
 *    "path": "/sdcard/trinity.mp3",
 *    "startTime": 2000,
 *    "endTime": 4000
 * }
 * json 参数解释:
 * path: 音乐的本地地址
 * startTime: 这个音乐的开始时间
 * endTime: 这个音乐的结束时间 4000代表这个音乐从开始时间到结束时间播放2秒钟
 */
val actionId = mVideoEditor.addMusic(config)
  • 删除背景音乐
/**
* 删除背景音乐
* @param actionId 必须为添加背景音乐时返回的actionId
*/
mVideoEditor.deleteMusic(actionId)

添加特效

  • 添加普通滤镜
/**
* 添加滤镜
* 如: content.json的绝对路径为 /sdcard/Android/com.trinity.sample/cache/filters/config.json
* 传入的路径只需要 /sdcard/Android/com.trinity.sample/cache/filters 即可
* 如果当前路径不包含config.json则添加失败
* 具体json内容如下:
* {
*  "type": 0,
*  "intensity": 1.0,
*  "lut": "lut_124/lut_124.png"
* }
*
* json 参数解释:
* type: 保留字段, 目前暂无作用
* intensity: 滤镜透明度, 0.0时和摄像头采集的无差别
* lut: 滤镜颜色表的地址, 必须为本地地址, 而且为相对路径
*      sdk内部会进行路径拼接
* @param configPath 滤镜config.json的父目录
* @return 返回当前滤镜的唯一id
*/
val actionId = mVideoEditor.addFilter(config)
  • 更新滤镜
/**
* 更新滤镜
* @param configPath config.json的路径, 目前对称addFilter说明
* @param startTime 滤镜的开始时间
* @param endTime 滤镜的结束时间
* @param actionId 需要更新哪个滤镜, 必须为addFilter返回的actionId
*/
mVideoEditor.updateFilter(config, 0, 2000, actionId)
  • 删除滤镜
 /**
   * 删除滤镜
   * @param actionId 需要删除哪个滤镜, 必须为addFilter时返回的actionId
   */
mVideoEditor.deleteFilter(actionId)   
  • 添加抖音特效
/**
* 添加特效
* 如: content.json的绝对路径为 /sdcard/Android/com.trinity.sample/cache/effects/config.json
* 传入的路径只需要 /sdcard/Android/com.trinity.sample/cache/effects 即可
* 如果当前路径不包含config.json则添加失败
* @param configPath 滤镜config.json的父目录
* @return 返回当前特效的唯一id
*/
val actionId = mVideoEditor.addAction(configPath)
  • 更新抖音特效
/**
* 更新指定特效
* @param startTime 特效的开始时间
* @param endTime 特效的结束时间
* @param actionId 需要更新哪个特效, 必须为addAction返回的actionId
*/
mVideoEditor.updateAction(0, 2000, actionId)
  • 删除抖音特效
/**
* 删除一个特效
* @param actionId 需要删除哪个特效, 必须为addAction返回的actionId
*/
mVideoEditor.deleteAction(actionId)

开始预览

  • 准备
mVideoEditor.prepare()
  • 播放
/**
 * @param repeat 是否循环播放
 */
mVideoEditor.play(repeat)
  • 暂停
mVideoEditor.pause()
  • 继续播放
mVideoEditor.resume()
  • 停止播放
mVideoEditor.stop()

释放资源

mVideoEditor.destroy()

导出视频

  • 创建导出实例
val export = TrinityCore.createExport(this)
  • 开始导出
/**
  * 开始导出
  * @param info 导出实体类
  * @param l 导出回调 包含成功 失败 和进度回调
  * @return Int ErrorCode.SUCCESS 为成功,其它为失败
  */
// 创建实体类, 必须传入视频输出地址  
val exportVideoInfo = VideoExportInfo("/sdcard/export.mp4")
// 使用硬解码
exportVideoInfo.mediaCodecDecode = true
// 使用硬编码
exportVideoInfo.mediaCodecEncode = true  
// 视频宽
exportVideoInfo.width = 544
// 视频高
exportVideoInfo.height = 960
// 帧率
exportVideoInfo.frameRate = 25
// 视频码率 2M
exportVideoInfo.videoBitRate = 2000
// 采样率
exportVideoInfo.sampleRate = 44100
// 声道数
exportVideoInfo.channelCount = 1
// 音频码率 128K
exportVideoInfo.audioBitRate = 128
export.export(exportVideoInfo, this)
  • 取消
export.cancel()
  • 释放
export.release()
Copyright 2019 Trinity, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版 (12)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/cnki_android/trinity.git
git@gitee.com:cnki_android/trinity.git
cnki_android
trinity
trinity
master

搜索帮助