ffmpeg - Dynamic letters and random position watermark to video?

余生长醉 提交于 2021-02-11 12:51:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/36362443/ffmpeg-dynamic-letters-and-random-position-watermark-to-video

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!