提前准备一个视频文件&水印图片
- 添加依赖
//https://github.com/yangjie10930/EpMedia
implementation 'com.github.yangjie10930:EpMedia:v1.0.1'
如果水印不在左上角,需要通过代码获取视频宽高等数据,调整水印位置。
示例代码:
val videoPath = "../inVideo.mp4"
val videoWidth = 1080
val videoHeight = 3140
val videoDuration = 2404650000L
val imgPath = File("../img.png")
val epVideo = EpVideo(videoPath)
val imgWidth = 384
val imgHeight = 128
epVideo.addDraw(//可增加多个水印
EpDraw(
imgPath.path,
max(videoWidth - imgWidth, 0),//水印起点x
max(videoHeight - imgHeight, 0),//水印起点y
imgWidth.toFloat(),//水印宽
imgHeight.toFloat(),//水印高
false,//是否gif
0,//水印起始时间
(videoDuration / 1000).toInt() + 1//水印结束时间(可超过视频全时长) 单位s
)
)
val file2 = File("../outVideo.mp4")
val outputOption = EpEditor.OutputOption(file2.path)
EpEditor.exec(epVideo, outputOption,
object : OnEditorListener {
override fun onSuccess() {
//SUCCESS
}
override fun onFailure() {
//Fail
}
override fun onProgress(progress: Float) {
}
})