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

查看:51
本文介绍了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 脚本调用命令,则可以使用随机数生成器并将其输入到命令中.drawtext 过滤器中包含一个随机函数,但是每帧都会对它进行评估,因此这将导致与文本进行伪乒乓游戏.

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天全站免登陆