当前位置:网站首页>想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
2022-07-27 07:43:00 【nginx】
给图片添加动效就能解决这个问题,动效可以让静态照片产生动态视频效果,能够将片段自然流畅地衔接起来,使整个作品更加地和谐。

这种动态效果,需要用户在专业的特效工具中手动设置锚点,才能产生流体运动效果,操作复杂。而现在,集成华为HMS Core视频编辑服务“一键动效”功能,就能让用户快速实现此效果,让手机相册中静态风景照,可以随时随地“动起来”。
HMS Core视频编辑服务“一键动效”功能
“一键动效”功能可以让静态风景图片实现视频动态效果,输入一张有天空或者水面的图片,“一键动效”让天空中的云朵飘动或者水面流动。开发者还可手动设置运动速度、运动方向、一键移除效果等,让动效更逼真。
下面我们就一起来实操一下如何集成华为视频编辑服务,实现“一键动效”功能:
1 . 开发准备
详细准备步骤可参考华为开发者联盟官网
2.编辑工程集成
2.1 设置应用的鉴权信息
可以通过api_key或者Access Token来设置应用鉴权信息。
· 通过setAccessToken方法设置Access Token,在应用启动时初始化设置一次即可,无需多次设置。
· 通过setApiKey方法设置api_key,在应用启动时初始化设置一次即可,无需多次设置。
MediaApplication.getInstance().setAccessToken("your access token");
2.2设置唯一标识ID,即License ID。
MediaApplication.getInstance().setApiKey("your ApiKey");
License ID是进行管控的有效凭证,您要保证设置License ID的唯一性。
初始化Editor运行环境,创建编辑工程,需要首先创建Editor对象并初始化其运行环境。当离开编辑工程时,应释放Editor实例。
MediaApplication.getInstance().setLicenseId("License ID");
(1)创建Editor对象
(2)指定预览窗口的布局位置
HuaweiVideoEditor editor = HuaweiVideoEditor.create(getApplicationContext());
预览窗口负责视频图像画面的渲染,由视频编辑原子能力SDK内部创建SurfaceView来实现。在创建窗口之前,需要在您的App中指定预览窗口的布局位置。
(3)初始化运行环境,如果License鉴权失败,会抛出LicenseException。
<LinearLayoutandroid:id="@+id/video_content_layout"android:layout_width="0dp"android:layout_height="0dp"android:background="@color/video_edit_main_bg_color"android:gravity="center"android:orientation="vertical" />// 指定预览窗口LinearLayout mSdkPreviewContainer = view.findViewById(R.id.video_content_layout);// 设置预览窗口承载的布局editor.setDisplay(mSdkPreviewContainer);
当Editor对象创建之后,此时还没有占用实际的系统资源,需要手动选择其环境初始化的时机,此时视频编辑原子能力SDK内部会创建必须的线程和定时器等。
3“一键动效”能力集成
try {editor.initEnvironment();} catch (LicenseException error) {SmartLog.e(TAG, "initEnvironment failed: " + error.getErrorMsg());finish();return;}
HMS Core视频编辑服务除了支持一键动效,还提供基础视频编辑、AI着色、专属滤镜、精彩片段、一键染发、人物追踪、人脸隐藏等视频创作能力,开发者可依据应用场景,在App中轻松完成视频编辑功能的集成。
// 初始化一键动效AI引擎imageAsset.initTimeLapseEngine(new HVEAIInitialCallback() {@Overridepublic void onProgress(int progress) {// 初始化进度}@Overridepublic void onSuccess() {// 初始化成功}@Overridepublic void onError(int errorCode, String errorMessage) {// 初始化失败}});// 初始化成功后,检查图片中是否有天空或者水面int motionType = -1;imageAsset.detectTimeLapse(new HVETimeLapseDetectCallback() {@Overridepublic void onResult(int state) {// 记录state作为添加一键动效AI特效的参数motionType = state;}});// skySpeed:天空的运动速度; skyAngle:天空的运动方向; waterSpeed:水面的运动速度; waterAngle:水面的运动方向HVETimeLapseEffectOptions options =new HVETimeLapseEffectOptions.Builder().setMotionType(motionType).setSkySpeed(skySpeed).setSkyAngle(skyAngle).setWaterAngle(waterAngle).setWaterSpeed(waterSpeed).build();// 添加一键动效AI特效imageAsset.addTimeLapseEffect(options, new HVEAIProcessCallback() {@Overridepublic void onProgress(int progress) {}@Overridepublic void onSuccess() {}@Overridepublic void onError(int errorCode, String errorMessage) {}});// 中断一键动效AI特效处理imageAsset.interruptTimeLapse();// 移除一键动效AI特效imageAsset.removeTimeLapseEffect();
了解更多详情>>
访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:GitHub、Gitee
关注我们,第一时间了解 HMS Core 最新技术资讯~
边栏推荐
- 软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
- yhb_ sysbench
- Chromedriver download - self use
- Resttemplate connection pool configuration
- 3D激光SLAM:LeGO-LOAM论文解读---摘要
- C语言:随机生成数+希尔排序
- [resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
- Do me a favor ~ don't pay attention, don't log in, a questionnaire in less than a minute
- 小程序支付管理-新版支付对接流程
- Usage scenarios for automated testing
猜你喜欢

DASCTF2022.07赋能赛密码wp

Clickhouse notes 1 | introduction, features | installation and use based on centos7 system | common data types | mergetree table engine | SQL operation

Hu related configuration

C#winform 窗体事件和委托结合用法

LeetCode56. 合并区间

Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money

An open source OA office automation system
![[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL](/img/05/41f48160fa7895bc9e4f314ec570c5.png)
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL

什么是真正的 HTAP ?(二)挑战篇

Understanding and learning of properties class and properties configuration file
随机推荐
Shell awk related exercises
「翻译」SAP变式物料的采购如何玩转?看看这篇你就明白了
glGetUniformLocation,glUniform4f
IDEA中文乱码怎么办
面试复盘五
[stonedb class] introductory lesson 1: popular science of database knowledge
The token verification of applet message push configuration failed. Please check and confirm
大家节日快乐哈
Bash: sudo: command not found in container
glGetUniformLocation,glUniform4f
容器内使用sudo报错bash: sudo: command not found解决
Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
Plato farm is expected to further expand its ecosystem through elephant swap
JS存取cookie示例
RPC remote procedure call
Abstract factory pattern
MySQL backup strategy
A priority SQL problem
剑指 Offer 58 - I. 翻转单词顺序
模仿大佬制作的宿舍门禁系统(三)