国庆
快乐
ffmpeg视频随机添加水印 – 海南仙岛

ffmpeg视频随机添加水印

2019年12月19日

这个是看到hostloc上一个网友提问的,并有网友回复的,所以在这里做下收藏和记录。

加水印,如何实现,左上,右上,左下,右下,四个角,每隔1分钟,随机换一个位置?

ffmpeg -i test.mp4 -i watermark.png -filter_complex "overlay='if(ld(0), if(lte(mod(t/60,1),0.05),st(0,0);NAN,ld(1)), st(0,1);if(lte(random(t),0.5),st(1,0),st(1,main_w-overlay_w));NAN)':'if(ld(0), if(lte(mod(t/60,1),0.05),st(0,0);NAN,ld(1)), st(0,1);if(lte(random(t),0.5),st(1,0),st(1,main_h-overlay_h));NAN)'" output.mp4

 

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

 

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 2 ’16 at 6:11
Sounds good. Can you point to a guide on how to format and submit a doc patch? Thanks. – Gyan Apr 2 ’16 at 7:07
Clone ffmpeg repo using git. Add name and email to git global 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). 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 2 ’16 at 18:03
Also see Using Git to develop FFmpeg. Most devs use git send-email but that involves some added complexity to setup. – llogan Apr 2 ’16 at 18:05
Thanks. Email sent. – Gyan Apr 3 ’16 at 9:13


sicnature ---------------------------------------------------------------------
I P 地 址: 98.80.143.34
区 域 位 置: 美国
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/3063.html

2条评论

  • 海南胡说 2020年05月10日在9:25 下午

    ffmpeg -threads 2 -y -i ./tmp/demo.mp4 -vf “drawtext=fontcolor=f9f1ea:shadowx=2:shadowy=2:fontsize=30:fontfile=msyh.ttf:textfile=text.txt:reload=1:y=h-line_h-52:x=w-(mod(8*n\\,w+tw)-tw/40)” -vcodec libx264 ./tmp/output.mp4

  • 海南胡说 2022年07月22日在10:10 上午

    添加环绕的水印(飞鸟、走马灯)

    ffmpeg.exe -i input.mp4 -vf drawtext=”fontsize=10:fontfile=/Windows/Fonts/arial.ttf:text=’Text Here’:x=if(eq(mod(n\,1200)\,0)\,rand(0\,(w-text_w))\,x):y=if(eq(mod(n\,1200)\,0)\,rand(0\,(h-text_h))\,y):enable=lt(mod(n\,1200)\,200)” -c:v libx264 -crf 17 -c:a copy output.mp4

    ffmpeg -i input.mp4 -loop 1 -i logo.png -filter_complex “[1]trim=0:30,fade=in:st=0:d=1:alpha=1,fade=out:st=9:d=1:alpha=1,loop=999:750:0,setpts=N/25/TB[w];[0][w]overlay=shortest=1:x=if(eq(mod(n\,200)\,0)\,sin(random(1))*W\,x):y=if(eq(mod(n\,200)\,0)\,sin(random(1))*H\,y)” output.mpg

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注