Skip to content

Commit f66e207

Browse files
committed
Allow additional arguments on watermark filter
Make positions optional (use -1 for posX and posY) and then use the setAddArgument() method
1 parent 032deed commit f66e207

File tree

16 files changed

+141
-47
lines changed

16 files changed

+141
-47
lines changed

Changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# JAVE2
22

33
## Changelog
4-
- **2.7.0**
4+
- **2.7.1**
5+
- Prepare for next dev cycle
6+
- Allow additional arguments on watermark filter
7+
- Make positions optional (use -1 for posX and posY) and then use the setAddArgument() method
8+
- **2.7.1-SNAPSHOT**
59
- Make FFMPEGLocator.createExecutor() to allow it to be used in other contexts
610
- added execute method to FFMPEGExecutor to leave the ffmpeg processes running after JVM shutdown
711
- First implementation of drawtext filter

jave-all-deps/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>ws.schild</groupId>
55
<packaging>jar</packaging>
6-
<version>2.7.0</version>
6+
<version>2.7.1-SNAPSHOT</version>
77
<artifactId>jave-all-deps</artifactId>
88
<name>Jave all native dependencies package</name>
99
<description>The JAVE (Java Audio Video Encoder) library is Java wrapper on the
@@ -152,32 +152,32 @@
152152
<dependency>
153153
<groupId>ws.schild</groupId>
154154
<artifactId>jave-core</artifactId>
155-
<version>2.7.0</version>
155+
<version>2.7.1-SNAPSHOT</version>
156156
</dependency>
157157
<dependency>
158158
<groupId>ws.schild</groupId>
159159
<artifactId>jave-nativebin-win32</artifactId>
160-
<version>2.7.0</version>
160+
<version>2.7.1-SNAPSHOT</version>
161161
</dependency>
162162
<dependency>
163163
<groupId>ws.schild</groupId>
164164
<artifactId>jave-nativebin-win64</artifactId>
165-
<version>2.7.0</version>
165+
<version>2.7.1-SNAPSHOT</version>
166166
</dependency>
167167
<dependency>
168168
<groupId>ws.schild</groupId>
169169
<artifactId>jave-nativebin-linux32</artifactId>
170-
<version>2.7.0</version>
170+
<version>2.7.1-SNAPSHOT</version>
171171
</dependency>
172172
<dependency>
173173
<groupId>ws.schild</groupId>
174174
<artifactId>jave-nativebin-linux64</artifactId>
175-
<version>2.7.0</version>
175+
<version>2.7.1-SNAPSHOT</version>
176176
</dependency>
177177
<dependency>
178178
<groupId>ws.schild</groupId>
179179
<artifactId>jave-nativebin-osx64</artifactId>
180-
<version>2.7.0</version>
180+
<version>2.7.1-SNAPSHOT</version>
181181
</dependency>
182182
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
183183
<dependency>

jave-core-test-java11/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>ws.schild</groupId>
55
<packaging>jar</packaging>
6-
<version>2.7.0</version>
6+
<version>2.7.1-SNAPSHOT</version>
77
<artifactId>jave-core-test-java11</artifactId>
88
<properties>
99
<maven.compiler.source>11</maven.compiler.source>
@@ -38,32 +38,32 @@
3838
<dependency>
3939
<groupId>ws.schild</groupId>
4040
<artifactId>jave-core</artifactId>
41-
<version>2.7.0</version>
41+
<version>2.7.1-SNAPSHOT</version>
4242
</dependency>
4343
<dependency>
4444
<groupId>ws.schild</groupId>
4545
<artifactId>jave-nativebin-win32</artifactId>
46-
<version>2.7.0</version>
46+
<version>2.7.1-SNAPSHOT</version>
4747
</dependency>
4848
<dependency>
4949
<groupId>ws.schild</groupId>
5050
<artifactId>jave-nativebin-win64</artifactId>
51-
<version>2.7.0</version>
51+
<version>2.7.1-SNAPSHOT</version>
5252
</dependency>
5353
<dependency>
5454
<groupId>ws.schild</groupId>
5555
<artifactId>jave-nativebin-linux32</artifactId>
56-
<version>2.7.0</version>
56+
<version>2.7.1-SNAPSHOT</version>
5757
</dependency>
5858
<dependency>
5959
<groupId>ws.schild</groupId>
6060
<artifactId>jave-nativebin-linux64</artifactId>
61-
<version>2.7.0</version>
61+
<version>2.7.1-SNAPSHOT</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>ws.schild</groupId>
6565
<artifactId>jave-nativebin-osx64</artifactId>
66-
<version>2.7.0</version>
66+
<version>2.7.1-SNAPSHOT</version>
6767
</dependency>
6868
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
6969
<dependency>

jave-core-test/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>ws.schild</groupId>
55
<packaging>jar</packaging>
6-
<version>2.7.0</version>
6+
<version>2.7.1-SNAPSHOT</version>
77
<artifactId>jave-core-test</artifactId>
88
<properties>
99
<maven.compiler.source>1.8</maven.compiler.source>
@@ -38,32 +38,32 @@
3838
<dependency>
3939
<groupId>ws.schild</groupId>
4040
<artifactId>jave-core</artifactId>
41-
<version>2.7.0</version>
41+
<version>2.7.1-SNAPSHOT</version>
4242
</dependency>
4343
<dependency>
4444
<groupId>ws.schild</groupId>
4545
<artifactId>jave-nativebin-win32</artifactId>
46-
<version>2.7.0</version>
46+
<version>2.7.1-SNAPSHOT</version>
4747
</dependency>
4848
<dependency>
4949
<groupId>ws.schild</groupId>
5050
<artifactId>jave-nativebin-win64</artifactId>
51-
<version>2.7.0</version>
51+
<version>2.7.1-SNAPSHOT</version>
5252
</dependency>
5353
<dependency>
5454
<groupId>ws.schild</groupId>
5555
<artifactId>jave-nativebin-linux32</artifactId>
56-
<version>2.7.0</version>
56+
<version>2.7.1-SNAPSHOT</version>
5757
</dependency>
5858
<dependency>
5959
<groupId>ws.schild</groupId>
6060
<artifactId>jave-nativebin-linux64</artifactId>
61-
<version>2.7.0</version>
61+
<version>2.7.1-SNAPSHOT</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>ws.schild</groupId>
6565
<artifactId>jave-nativebin-osx64</artifactId>
66-
<version>2.7.0</version>
66+
<version>2.7.1-SNAPSHOT</version>
6767
</dependency>
6868
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
6969
<dependency>

jave-core-test/src/test/java/ws/schild/jave/filters/VideoFilterTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,27 @@ public void testVideoFilter3() throws Exception {
9595
encoder.encode(new MultimediaObject(source), target, attrs);
9696
assertTrue( target.exists(), "Output file missing");
9797
}
98+
99+
100+
@Test
101+
public void testVideoFilter4() throws Exception {
102+
System.out.println("testVideoFilter4");
103+
104+
File source = new File(getResourceSourcePath(), "testfile3.wmv ");
105+
File target = new File(getResourceTargetPath(), "testVideoFilter4.mp4");
106+
if (target.exists())
107+
{
108+
target.delete();
109+
}
110+
VideoDrawtext vf= new VideoDrawtext("testVideoFilter4 center", -1, -1, "Arial", null, 30, new Color("ffffff", "44"));
111+
vf.setAddArgument("x=(w-text_w)/2:y=(h-text_h)/2");
112+
vf.setShadow(new Color("000000", "44"), 2, 2);
113+
VideoAttributes videoAttributes= new VideoAttributes();
114+
videoAttributes.addFilter(vf);
115+
EncodingAttributes attrs = new EncodingAttributes();
116+
attrs.setVideoAttributes(videoAttributes);
117+
Encoder encoder = new Encoder();
118+
encoder.encode(new MultimediaObject(source), target, attrs);
119+
assertTrue( target.exists(), "Output file missing");
120+
}
98121
}

jave-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>ws.schild</groupId>
55
<artifactId>jave-core</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.7.0</version>
7+
<version>2.7.1-SNAPSHOT</version>
88
<name>Jave core package</name>
99
<description>The JAVE (Java Audio Video Encoder) library is Java wrapper on the
1010
ffmpeg project. Developers can take take advantage of JAVE2 to transcode

jave-core/src/main/java/ws/schild/jave/DefaultFFMPEGLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class DefaultFFMPEGLocator extends FFMPEGLocator {
4343
* Trace the version of the bundled ffmpeg executable. It's a counter: every
4444
* time the bundled ffmpeg change it is incremented by 1.
4545
*/
46-
private static final String MY_EXE_VERSION = "2.7.0";
46+
private static final String MY_EXE_VERSION = "2.7.1-SNAPSHOT";
4747

4848
/**
4949
* The ffmpeg executable file path.

jave-core/src/main/java/ws/schild/jave/Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public static String buildTimeDuration(long milis)
5555

5656
/**
5757
* Escape all special characters []=;, to be safe to use in command line
58-
* @param argumentIn
59-
* @return
58+
* @param argumentIn input argument to escape
59+
* @return escaped string
6060
*/
6161
public static String escapeArgument(String argumentIn)
6262
{

jave-core/src/main/java/ws/schild/jave/filters/VideoDrawtext.java

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
public class VideoDrawtext extends VideoFilter {
2323

2424
private String watermarkText= null;
25-
private int posX= 0;
26-
private int posY= 0;
25+
private int posX= -1;
26+
private int posY= -1;
2727

28-
private String fontName= null;
28+
private String fontName= "Arial";
2929
private File fontFile= null;
3030
private float fontSize= 10;
3131
private Color fontColor= null;
@@ -41,12 +41,25 @@ public class VideoDrawtext extends VideoFilter {
4141

4242
private int borderWidth= 0;
4343
private Color borderColor= null;
44+
private String addArgument= null;
4445

4546
/**
46-
*
4747
* @param watermarkText Text to be used as watermark
48-
* @param posX X Position of watermark text (From the left)
49-
* @param posY Y Position of watermark text (From the top)
48+
* @param fontColor Color of font
49+
*/
50+
public VideoDrawtext(
51+
String watermarkText,
52+
Color fontColor
53+
) throws IllegalArgumentException
54+
{
55+
this.watermarkText= watermarkText;
56+
this.fontColor= fontColor;
57+
}
58+
59+
/**
60+
* @param watermarkText Text to be used as watermark
61+
* @param posX X Position of watermark text (From the left) ignored if posX &amp; posY are both -1
62+
* @param posY Y Position of watermark text (From the top) ignored if posX &amp; posY are both -1
5063
* @param fontName Use this font (Can be null, but then we need a fontFile)
5164
* @param fontFile Truetype font file (Only required when fontName is NULL)
5265
* @param fontSize Font size
@@ -71,6 +84,7 @@ public VideoDrawtext(
7184
this.fontColor= fontColor;
7285
}
7386

87+
7488
/**
7589
*
7690
* @param shadowColor Color of shadow
@@ -113,6 +127,8 @@ public int getPosX() {
113127
}
114128

115129
/**
130+
* ignored if posX &amp; posY are both -1
131+
*
116132
* @param posX the posX to set
117133
* @return this instance
118134
*/
@@ -122,6 +138,8 @@ public VideoDrawtext setPosX(int posX) {
122138
}
123139

124140
/**
141+
* ignored if posX &amp; posY are both -1
142+
*
125143
* @return the posY
126144
*/
127145
public int getPosY() {
@@ -336,17 +354,61 @@ public VideoDrawtext setLineSpacing(int lineSpacing) {
336354
this.lineSpacing = lineSpacing;
337355
return this;
338356
}
339-
357+
358+
/**
359+
* @return the addArgument
360+
*/
361+
public String getAddArgument() {
362+
return addArgument;
363+
}
364+
365+
/**
366+
* Add an additional argument to the command line
367+
* https://superuser.com/questions/939357/position-text-on-bottom-right-corner
368+
*
369+
* Bottom right
370+
* x=w-tw:y=h-th
371+
* Bottom right with 10 pixel padding
372+
* x=w-tw-10:y=h-th-10
373+
* Top right
374+
* x=w-tw
375+
* Top right with 10 pixel padding
376+
* x=w-tw-10:y=10
377+
* Top left
378+
* x=0:y=0
379+
* Top left with 10 pixel padding
380+
* x=10:y=10
381+
* Bottom left
382+
* y=h-th
383+
* Bottom left with 10 pixel padding
384+
* x=10:h-th-10
385+
* centered
386+
* x=(w-text_w)/2:y=(h-text_h)/2
387+
*
388+
* Can be used to speicfy other positions like "x=(w-text_w)/2:y=(h-text_h)/2"
389+
* for centered text water mark
390+
*
391+
* @param addArgument the addArgument to set
392+
* @return this instance
393+
*/
394+
public VideoDrawtext setAddArgument(String addArgument) {
395+
this.addArgument = addArgument;
396+
return this;
397+
}
398+
340399
@Override
341400
public String getExpression()
342401
{
343402
StringBuilder sb= new StringBuilder();
344403
sb.append("drawtext=text='");
345404
sb.append(Utils.escapeArgument(watermarkText));
346-
sb.append("':x=");
347-
sb.append(Integer.toString(posX));
348-
sb.append("':y=");
349-
sb.append(Integer.toString(posY));
405+
if (posX != -1 && posY != -1)
406+
{
407+
sb.append("':x=");
408+
sb.append(Integer.toString(posX));
409+
sb.append("':y=");
410+
sb.append(Integer.toString(posY));
411+
}
350412
if (fontName != null)
351413
{
352414
sb.append(":font=");
@@ -394,6 +456,11 @@ else if (fontFile != null)
394456
sb.append(":borderw=");
395457
sb.append(Integer.toString(boxBorderWidth));
396458
}
459+
if (addArgument != null)
460+
{
461+
sb.append(":");
462+
sb.append(addArgument);
463+
}
397464

398465
return sb.toString();
399466
}

jave-example/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>ws.schild</groupId>
55
<packaging>jar</packaging>
6-
<version>2.7.0</version>
6+
<version>2.7.1-SNAPSHOT</version>
77
<artifactId>jave-example</artifactId>
88
<properties>
99
<maven.compiler.source>1.8</maven.compiler.source>
@@ -66,12 +66,12 @@
6666
<dependency>
6767
<groupId>ws.schild</groupId>
6868
<artifactId>jave-core</artifactId>
69-
<version>2.7.0</version>
69+
<version>2.7.1-SNAPSHOT</version>
7070
</dependency>
7171
<dependency>
7272
<groupId>ws.schild</groupId>
7373
<artifactId>jave-nativebin-linux32</artifactId>
74-
<version>2.7.0</version>
74+
<version>2.7.1-SNAPSHOT</version>
7575
</dependency>
7676
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
7777
<dependency>

0 commit comments

Comments
 (0)