ffmpeg-视频的动态字母和随机位置水印? [英] ffmpeg - Dynamic letters and random position watermark to video?

查看:344
本文介绍了ffmpeg-视频的动态字母和随机位置水印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作在线课程,并且为了避免盗版传播,我想在视频上加上水印(包括个人用户信息),以便不能将其上载到共享网站.现在最困难的部分是:我将在视频过程中每30秒在3/4个随机位置移动水印一次.ffmpeg有可能吗?

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?

推荐答案

编辑:这是LN链接中答案的改编版,它将每30秒随机化一次位置,而不会重复:

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


较旧的答案

您可以使用以下命令:

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

此处,三个位置旋转一次,每30秒发生一次更改.每个 x:y 参数都是手动设置的.如果要从Shell脚本调用命令,则可以使用随机数生成器并将其输入命令中.抽奖文字过滤器中包含一个随机函数,但是会对其进行评估,每帧 ,这样将导致带有该文本的伪乒乓游戏.

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.

这篇关于ffmpeg-视频的动态字母和随机位置水印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆