I am making an online course, and to avoid piracy distribution I thought to put watermarks on the videos (including personal user information) so it cannot upload to sharing websites. Now the hard part: I would move the watermark during the video, in 3/4 random positions, every 30 seconds. It is possibile with ffmpeg?
Asked
Active
Viewed 5,187 times
0
-
Duplicate of [Making jumping text watermark](http://stackoverflow.com/questions/30291331/making-jumping-text-watermark). – llogan Apr 01 '16 at 19:15
-
**The "ffmpeg" tag is only allowed for programmatic use of the ffmpeg API** - Questions about the command-line use should be asked on Super-user or Video-production. – Top-Master Apr 22 '23 at 07:30
-
yeah but you can use the command line on a server for programmatic use, no? – sekmo May 04 '23 at 08:55
1 Answers
6
Edit: this is an adaptation of the answer in LN's link, which will randomize the position every 30 seconds with no repeats:
ffmpeg -i input.mp4 \
-vf \
"drawtext=fontfile=font.ttf:fontsize=80:fontcolor=yellow@0.5:text='studentname': \
x=if(eq(mod(t\,30)\,0)\,rand(0\,(W-tw))\,x): \
y=if(eq(mod(t\,30)\,0)\,rand(0\,(H-th))\,y)" \
-c:v libx264 -crf 23 -c:a copy output.mp4
Older answer
You can use a command like the one below:
ffmpeg -i input.mp4 \
-vf \
"drawtext=fontfile=font.ttf:fontsize=80:fontcolor=yellow@0.5: \
text='studentname':x=200:y=350:enable='between(mod(t\,30*3),0,30)', \
drawtext=fontfile=font.ttf:fontsize=80:fontcolor=yellow@0.5: \
text='studentname':x=1000:y=600:enable='between(mod(t\,30*3),31,60)', \
drawtext=fontfile=font.ttf:fontsize=80:fontcolor=yellow@0.5: \
text='studentname':x=450:y=50:enable='between(mod(t\,30*3),61,90)'" \
-c:v libx264 -crf 23 -c:a copy output.mp4
Here, three positions are rotated with a change occurring every 30 seconds. Each x:y
parameter is manually set. If you're calling the command from a shell script, you can use a random number generator and feed that into the command. There is a random function included in the drawtext filter, but it is evaluated each frame, so that will result in a pseudo ping pong game with the text.
-
It is an interesting example, and I've seen enough similar questions like this that I think it could be useful to add it to the drawtext examples in `doc/filters.texi` if you feel like submitting a patch. – llogan Apr 02 '16 at 06:11
-
Sounds good. Can you point to a guide on how to format and submit a doc patch? Thanks. – Gyan Apr 02 '16 at 07:07
-
[Clone ffmpeg repo using git](https://ffmpeg.org/download.html). [Add name and email to git global config](https://wiki.videolan.org/git#Configure_your_global_git_config) and navigate to `ffmpeg` directory. Always rebase first: `git pull --rebase`. Make local branch: `git checkout -b drawrandom`. Make edits. Locally commit changes: `git commit -as` (see [example commit titles and messages](http://git.videolan.org/?p=ffmpeg.git;a=history;f=doc/filters.texi)). Review log `git log -p -2`, make patch: `git format-patch -o patches origin`. Email file in `patches` to ffmpeg-devel at ffmpeg. – llogan Apr 02 '16 at 18:03
-
Also see [Using Git to develop FFmpeg](https://ffmpeg.org/git-howto.html). Most devs use `git send-email` but that involves some added complexity to setup. – llogan Apr 02 '16 at 18:05
-
Can someone please explain logic and details of this expression from the example above: x=if(eq(mod(t\,30)\,0)\,rand(0\,(W-tw))\,x) ? I know that it's responsible for random repositioning by X axis, every 30 seconds. But how it all works - those: if, eq, mod, t, rand, \ ? – Vadim Dec 30 '19 at 20:30
-
The expression for x and y are of the form : `if(condition,then,else)`. If condition is true, the `then` clause is executed; if false, the `else` clause is executed. `eq(mod(t\,30)\,0)` is true only for `t=0,30,60,90...`. At those times, x and y are set to a random position which keeps the full text on screen. At all other times, the text remains still till the next change happens. – Gyan Dec 31 '19 at 05:08