2222public 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 & posY are both -1
62+ * @param posY Y Position of watermark text (From the top) ignored if posX & 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 & 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 & 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 }
0 commit comments