HarmonyOS鸿蒙Next中有相关的SDK可以实现视频剪辑功能吗?
HarmonyOS鸿蒙Next中有相关的SDK可以实现视频剪辑功能吗? 有相关的SDK可以实现视频剪辑功能吗?有没有文档或者三方库
【解决方案】
-
使用提供视频剪辑能力的三方库videotrimmer,使用前要进行安装。
ohpm install [@ohos](/user/ohos)/videotrimmer
具体demo如下:使用videotrimmer实现视频剪辑。
-
使用基于Ffmpeg封装的音视频处理三方库mp4parser实现视频裁剪,使用前需要先进行安装。
ohpm install [@ohos](/user/ohos)/mp4parser
具体使用说明可参考视频裁剪。
更多关于HarmonyOS鸿蒙Next中有相关的SDK可以实现视频剪辑功能吗?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
【背景知识】
AVImageGenerator:视频缩略图获取类,用于从视频资源中获取缩略图。
PanGesture:滑动手势事件,当滑动的最小距离达到设定的最小值时触发滑动手势事件。
[@ohos/mp4parser](https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Fmp4parser):一个读取、写入操作音视频文件编辑的工具。
【参考方案】:
可参考拖动时间轴剪辑视频时长示例,基于PanGesture实现视频剪辑起止时间拖动选择的功能,使用fetchFrameByTime获取视频对应时间的缩略图,使用第三方库[@ohos/mp4parser](https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Fmp4parser)实现视频剪辑。
- 使用PanGesture实现视频剪辑起止时间的拖动选择,拖动过程中,实时刷新拖动位置对应的时间以及视频缩略图。
// Drag to set the start time
PanGesture({ fingers: 1 })
.onActionUpdate(async event => {
if (this.leftWidthOrigin + event.offsetX >= 0 &&
this.leftWidthOrigin + event.offsetX + this.oneSecondWidth <= this.rightWidth &&
this.canDrag) {
this.canDrag = false
this.leftWidth = this.leftWidthOrigin + event.offsetX
this.startTime = (this.leftWidth / this.thumbnailWidth) / 4 * this.fullTime
this.currentTime = this.startTime
this.videoController.pause()
this.isVideoStart = false
this.videoController.setCurrentTime(this.currentTime / 1000)
this.currentOffset = this.currentTime / this.fullTime * this.thumbnailWidth * 4
// Refresh the time corresponding to the drag position
this.currentTimeShow = VideoUtils.formatDuration(this.currentTime)
if (!this.isPlayed) {
// Refresh the video thumbnail corresponding to the dragged position
this.pixelMapShow = await this.fetchFrameByTime(this.currentTime * 1000)
}
this.canDrag = true
}
})
- 使用fetchFrameByTime获取视频对应时间的缩略图。
// Obtain video frame images
async fetchFrameByTime(time: number): Promise<image.PixelMap | undefined> {
let pixelMap = await this.avImageGenerator?.fetchFrameByTime(time,
media.AVImageQueryOptions.AV_IMAGE_QUERY_CLOSEST_SYNC, this.videoSize.photoSize);
return pixelMap
}
- 使用第三方库[@ohos/mp4parser](https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Fmp4parser)实现视频剪辑。
// Based on the provided start and end times, the original video will be edited, and the edited video will be saved to a new file
MP4Parser.ffmpegCmd(`ffmpeg -y -i ${videoDir}/InputVideo.mp4 -ss ${sTime} -t ${eTime} -c copy ${videoDir}/OutputVideo.mp4`,
{
callBackResult: (code: number) => {
...
},
}
);
HarmonyOS Next提供了多媒体SDK支持视频剪辑功能。该SDK包含视频编辑、滤镜添加、特效处理等核心接口,支持格式包括MP4、MOV等常见格式。开发者可通过DevEco Studio集成相关API实现基础剪辑操作。
是的,HarmonyOS Next提供了多媒体SDK支持视频剪辑功能,包括视频裁剪、拼接、滤镜、转场效果等。相关API可通过HarmonyOS Developer官网的“多媒体开发指南”查阅,具体路径为:文档 → 开发 → 多媒体 → 视频处理。目前暂未开放第三方剪辑库,建议直接使用官方SDK进行开发。