Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
978 views
in Technique[技术] by (71.8m points)

ffmpeg - Dynamic letters and random position watermark to video?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:[email protected]: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:[email protected]: 
 text='studentname':x=200:y=350:enable='between(mod(t,30*3),0,30)', 
 drawtext=fontfile=font.ttf:fontsize=80:[email protected]: 
 text='studentname':x=1000:y=600:enable='between(mod(t,30*3),31,60)', 
 drawtext=fontfile=font.ttf:fontsize=80:[email protected]: 
 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...