Skip to content

Commit 4f958e5

Browse files
author
Administrator
committed
增加文字水印和图片水印的显示周期和起始时间。
1 parent 23b5086 commit 4f958e5

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

joevideolib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
android {
44
compileSdkVersion 25
5-
buildToolsVersion "25.0.0"
5+
buildToolsVersion '26.0.2'
66

77
defaultConfig {
88
minSdkVersion 16

joevideolib/src/main/java/VideoHandle/EpDraw.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class EpDraw {
1414
private float picHeight;//图片的高
1515
private boolean isAnimation;//是否是动图
1616

17+
private String time = "";//起始结束时间
18+
1719
private String picFilter;//图片滤镜
1820

1921
public EpDraw(String picPath, int picX, int picY, float picWidth, float picHeight, boolean isAnimation) {
@@ -25,6 +27,16 @@ public EpDraw(String picPath, int picX, int picY, float picWidth, float picHeigh
2527
this.isAnimation = isAnimation;
2628
}
2729

30+
public EpDraw(String picPath, int picX, int picY, float picWidth, float picHeight, boolean isAnimation,int start,int end) {
31+
this.picPath = picPath;
32+
this.picX = picX;
33+
this.picY = picY;
34+
this.picWidth = picWidth;
35+
this.picHeight = picHeight;
36+
this.isAnimation = isAnimation;
37+
time = ":enable=between(t\\," + start + "\\," + end + ")";
38+
}
39+
2840
public String getPicPath() {
2941
return picPath;
3042
}
@@ -53,6 +65,10 @@ public String getPicFilter() {
5365
return picFilter == null ? "" : (picFilter + ",");
5466
}
5567

68+
public String getTime() {
69+
return time;
70+
}
71+
5672
public void setPicFilter(String picFilter) {
5773
this.picFilter = picFilter;
5874
}

joevideolib/src/main/java/VideoHandle/EpEditor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public void exec(EpVideo epVideo, OutputOption outputOption, OnEditorListener on
7272
} else {
7373
cmd.append("[outo").append(i - 1).append("]").append("[outv").append(i + 1).append("]");
7474
}
75-
cmd.append("overlay=").append(epDraws.get(i).getPicX()).append(":").append(epDraws.get(i).getPicY());
75+
cmd.append("overlay=").append(epDraws.get(i).getPicX()).append(":").append(epDraws.get(i).getPicY())
76+
.append(epDraws.get(i).getTime());
7677
if (epDraws.get(i).isAnimation()) {
7778
cmd.append(":shortest=1");
7879
}
@@ -184,7 +185,8 @@ public void merge(List<EpVideo> epVideos, OutputOption outputOption, OnEditorLis
184185
for (int j = 0; j < epVideos.get(i).getEpDraws().size(); j++) {
185186
cmd.append("[outv").append(i).append("][p").append(i).append("a").append(j).append("]overlay=")
186187
.append(epVideos.get(i).getEpDraws().get(j).getPicX()).append(":")
187-
.append(epVideos.get(i).getEpDraws().get(j).getPicY());
188+
.append(epVideos.get(i).getEpDraws().get(j).getPicY())
189+
.append(epVideos.get(i).getEpDraws().get(j).getTime());
188190
if (epVideos.get(i).getEpDraws().get(j).isAnimation()) {
189191
cmd.append(":shortest=1");
190192
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package VideoHandle;
2+
3+
/**
4+
* Created by Administrator on 2017/11/8.
5+
*/
6+
7+
public class EpText {
8+
9+
private String textFitler;
10+
11+
/**
12+
* @param x 文字起始位置X
13+
* @param y 文字起始位置Y
14+
* @param size 文字的大小
15+
* @param color 文字的颜色
16+
* @param ttf 文字的字体文件路径
17+
* @param text 添加文字的内容
18+
* @param time 起始结束时间(传null的时候为一直显示)
19+
*/
20+
public EpText(int x, int y, float size, Color color, String ttf, String text, Time time) {
21+
this.textFitler = "drawtext=fontfile=" + ttf + ":fontsize=" + size + ":fontcolor=" + color.getColor() + ":x=" + x + ":y=" + y + ":text='" + text + "'" + (time == null ? "" : time.getTime());
22+
}
23+
24+
public String getTextFitler() {
25+
return textFitler;
26+
}
27+
28+
/**
29+
* 起始结束时间的类
30+
*/
31+
public static class Time {
32+
private String time;
33+
34+
public Time(int start, int end) {
35+
this.time = ":enable=between(t\\," + start + "\\," + end + ")";
36+
}
37+
38+
public String getTime() {
39+
return time;
40+
}
41+
}
42+
43+
/**
44+
* 颜色
45+
*/
46+
public enum Color {
47+
Red("Red"), Blue("Blue"), Yellow("Yellow"), Black("Black"), DarkBlue("DarkBlue"),
48+
Green("Green"), SkyBlue("SkyBlue"), Orange("Orange"), White("White"), Cyan("Cyan");
49+
private String color;
50+
51+
Color(String color) {
52+
this.color = color;
53+
}
54+
55+
public String getColor() {
56+
return color;
57+
}
58+
}
59+
}

joevideolib/src/main/java/VideoHandle/EpVideo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,26 @@ public Crop getCrop(){
173173
* @param y 文字的y坐标
174174
* @param ttf 文字字体的路径
175175
* @param text 添加的文字
176+
* @deprecated 废弃,采用EpText参数
176177
*/
178+
@Deprecated
177179
public EpVideo addText(int x, int y, float size, String color, String ttf, String text) {
178180
filter = getFilter();
179181
filter.append("drawtext=fontfile=" + ttf + ":fontsize=" + size + ":fontcolor=" + color + ":x=" + x + ":y=" + y + ":text='" + text + "'");
180182
return this;
181183
}
182184

185+
/**
186+
* 为视频添加文字(新增可以控制显示周期)
187+
*
188+
* @param epText 添加文字类
189+
*/
190+
public EpVideo addText(EpText epText) {
191+
filter = getFilter();
192+
filter.append(epText.getTextFitler());
193+
return this;
194+
}
195+
183196
/**
184197
* 为视频添加时间
185198
*

0 commit comments

Comments
 (0)