ffmpeg # drawtext 進(jìn)階

預(yù)備知識

https://ffmpeg.org/ffmpeg-utils.html

between(x, min, max)
Return 1 if x is greater than or equal to min and lesser than or equal to max, 0 otherwise.
...
gt(x, y)
Return 1 if x is greater than y, 0 otherwise.

gte(x, y)
Return 1 if x is greater than or equal to y, 0 otherwise.

...
if(x, y)
Evaluate x, and if the result is non-zero return the result of the evaluation of y, return 0 otherwise.

if(x, y, z)
Evaluate x, and if the result is non-zero return the evaluation result of y, otherwise the evaluation result of z.
...
lt(x, y)
Return 1 if x is lesser than y, 0 otherwise.

lte(x, y)
Return 1 if x is lesser than or equal to y, 0 otherwise.

...
mod(x, y)
Compute the remainder of division of x by y.

一些加文字的例子

  • 前5秒(包括)加文字
ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='test':x=50:y=50:enable='lte(t\,5)'   -y out.mp4
  • 從5秒(包括)之后加文字
ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='test':x=50:y=50:enable='gte(t\,5)'   -y out.mp4
  • 第10秒到20秒加文字
ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='test':x=50:y=50:enable='between(t\,10\,20)'   -y out.mp4
  • 切片的時候使用 比如每個切片10秒 對第二個切片的前5秒 加文字 也就是總文件的10~15秒 當(dāng)前切片的前5秒
ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=msyh.ttf:line_spacing=7:text='test':x=50:y=50:enable='between(t

+10\,0\,15)'   -y out.mp4
  • 顯示5秒 然后5秒不顯示 然后再顯示5秒 然后5秒不顯示; 依次。。。
ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='test':x=50:y=50:enable='lte(mod(t\,10)\,5)'   -y out.mp4
  • 5秒顯示hello 接著5秒顯示world 依次
ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='hello':x=50:y=50:enable='lte(mod(t

\,10)\,5)',drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='world':x=50:y=50:enable='gte(mod(t\,10)\,5)'   -y 

out.mp4
  • 文字從左向右移動 每幀移動2個像素
 ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=test.ttf:line_spacing=7:text='test':x=50+n*2:y=50  -y 
out.mp4
  • 打印real time
 ffmpeg -i bunny.mp4 -vf drawtext=fontcolor=white:fontsize=20:fontfile=test.ttf:line_spacing=7:text='%{localtime}':x=20:y=20 -vframes 600  -y out.mp4

References:

http://blog.threadblocked.com/2018/06/09/post1/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容