ni_quadra_drawtext
The ni_quadra_drawtext filter is based on FFmpeg’s native drawtext filter. It draws text on top of a video frame using the libfreetype library and works with NETINT hardware frame only. The ni_quadra_drawtext filter parameters are identical to those of FFmpeg drawtext filter when drawing only one drawtext. Reference FFmpeg documentation of drawtext parameters for details.
The ni_quadra_drawtext filter only supports NETINT hardware AVFrame as input and output.
The ni_quadra_drawtext filter only accepts limited color range video (also known as “tv” range). While full range video (also known as “pc” range) will be accepted; the ni_quadra_drawtext filter will clamp to limited color range video before processing. This clamp will cause a slight color shift in the output video.
The drawtext filters compilation has dependency of freetype and fontconfig libraries. On Linux hosts these libraries can be installed by the following commands:
sudo apt-get install libfreetype6-dev
sudo apt-get install libfontconfig1-dev
In addition, building of FFmpeg/libav needs to have those libraries enabled. A configurable option (disabled by default) is added into build_ffmpeg.sh to enable this:
build_ffmpeg.sh --nidrawtext
This filter supports a maximum input resolution of 7040x7040.
Altering parameters via commands is only supported for FFmpeg 4.3 and above.
Parameters
The following are the ni_quadra_drawtext parameters when drawing multiple texts simultaneously:
text/(t0-t31)
Specify the text to write.
| Default | Null |
x, y/(x0-x31), (y0-y31)
The expressions which specify the top left corner coordinates of the text.
| Default | 0 |
font/(f0-f31)
Specify the font of the text to write.
| Default | Sans |
fontcolor/(fc0-fc31)
Specify the color of the text to write.
| Default | black |
fontsize/(fs0-fs31)
Specify the size of the text to write.
| Default | 36 |
fontcolor_expr/(fc_expr0 -fc_expr31)
Specify the color of the text to write by RGB.
If fontcolor_expr was set, it will overwrite the corresponding fontcolor setting.
| Default | NULL |
boxcolor/(bc0-bc31)
Specify the color of the text box.
| Default | white |
boxborderw/(bb0-bb31)
Specify the box border width (padding)
| Default | 0 |
| Supported Values | - all - vert|horiz - top|right|bottom|left. |
Commands
ni_quadra_drawtext filter supports altering parameters via commands, but it only supports for ffmpeg4.3 and above.
reinit: Alter existing filter parameters.
Syntax for the argument is the same as for filter invocation, e.g.
fontsize=56:fontcolor=green:text='Hello World'
If the entire argument can’t be parsed or applied as valid values then the filter will continue with its existing parameters.
The following example shows how to print a time stamp onto a transcoded H.264 stream using ni_quadra_drawtext, and can draw up to 32 texts simultaneously:
ffmpeg -y -c:v h264_ni_quadra_dec -xcoder-params "out=hw" -i input1080p.h264 -filter_complex "ni_quadra_drawtext=font=Sans:fontcolor=White:text='%{pts\:localtime\:1456007118}':x=1050:y=680[out]" -map [out] -c:v h264_ni_quadra_enc output.h264
ffmpeg -y -c:v h264_ni_quadra_dec -xcoder-params "out=hw" -i input1080p.264 -vf "ni_quadra_drawtext=f0=Sans:fc_expr0=#0000ff:fs0=36:t0=hello:x0=100:y0=100:f1=Sans:t1=hello1:fc_expr1=#00ff00:fs1=36:x1=300:y1=100" -c:v h264_ni_quadra_enc output2.h264
ffmpeg -y -c:v h264_ni_quadra_dec -xcoder-params "out=hw" -i input1080p.h264 -filter_complex "ni_quadra_drawtext=f0=Sans:fs0=36:t0=hello:x0=100:y0=100:t1=hello1:fs1=36:x1=300:y1=100:t2=hello2:fs2=36:x2=500:y2=100:t3=hello3:fs3=36:x3=700:y3=100:t4=hello4:fs4=36:x4=900:y4=100:t5=hello5:fs5=36:x5=1100:y5=100:t6=hello6:fs6=36:x6=1300:y6=100:t7=hello7:fs7=36:x7=1500:y7=100:t8=hello8:fs8=36:x8=1700:y8=100:t9=hello9:fs9=36:x9=100:y9=200:t10=hello10:fs10=36:x10=300:y10=200:t11=hello11:fs11=36:x11=500:y11=200:t12=hello12:fs12=36:x12=700:y12=200:t13=hello13:fs13=36:x13=900:y13=200:t14=hello14:fs14=36:x14=1100:y14=200:t15=hello15:fs15=36:x15=1300:y15=200:t16=hello16:fs16=36:x16=1500:y16=200:t17=hello17:fs17=36:x17=1700:y17=200:t18=hello18:fs18=36:x18=100:y18=500:t19=hello19:fs19=36:x19=300:y19=500:t20=hello20:fs20=36:x20=500:y20=500:t21=hello21:fs21=36:x21=700:y21=500:t22=hello22:fs22=36:x22=900:y22=500:t23=hello23:fs23=36:x23=1100:y23=500:t24=hello24:fs24=36:x24=1300:y24=500:t25=hello25:fs25=36:x25=1500:y25=500:t26=hello26:fs26=36:x26=1700:y26=500:t27=hello27:fs27=36:x27=100:y27=900:t28=hello28:fs28=36:x28=300:y28=900:t29=hello29:fs29=36:x29=500:y29=900:t30=hello30:fs30=36:x30=700:y30=900:t31=hello31:fs31=36:x31=900:y31=900[out]" -map [out] -c:v h264_ni_quadra_enc output.h264