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 ---------------------------------------------------------------------
Your current IP address is: 3.235.193.1
Your IP address location: 美国 弗吉尼亚州阿什本amazon数据中心
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://myzhenai.com/post/3063.html

1 评论

  • 海南胡说 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

发表评论

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