1

I'm using FFmpeg to overlay text on videos, and I find the process to be quite slow. The operation becomes especially slow when I add complex drawtext filters. I'm running this on a MacBook Pro with M1 Pro and 32GB RAM, yet FFmpeg is using only 20% of the CPU at most. I'd like to speed up the process without compromising on quality.

Here's the FFmpeg command I'm using:

ffmpeg -i input.mp4 \
-vf "drawtext=fontfile='/path/to/font.ttf':textfile='text1.txt':\
x=(w-text_w)/2:y=(h-text_h)/2:fontsize=65:[email protected]:\
bordercolor=black:borderw=9:shadowcolor=black:shadowx=5:shadowy=5:\
box=1:[email protected]:boxborderw=20:fix_bounds=1:line_spacing=10:\
enable='between(t,0,5)',\
drawtext=fontfile='/path/to/font.ttf':textfile='text2.txt':\
x=(w-text_w)/2:y=(h-text_h)/2:fontsize=65:[email protected]:\
bordercolor=black:borderw=9:shadowcolor=black:shadowx=5:shadowy=5:\
box=1:[email protected]:boxborderw=20:fix_bounds=1:line_spacing=10:\
enable='between(t,5,10)'" \
-b:v 5000k -c:v h264_videotoolbox -threads 0 -y output.mp4

Any suggestions on how to optimize this command to better utilize the CPU and improve the speed of text overlay with FFmpeg?

2
  • Try drawing the text over an image with transparent background (create a PNG image from advanced), then overlay the image over the video instead of drawing the text (make the resolution of the PNG the smallest size that still contains the text). Check if it's faster...
    – Rotem
    Commented Sep 18, 2023 at 18:24
  • @Rotem I tried it, and It was slower
    – mlika
    Commented Sep 22, 2023 at 18:05

0

You must log in to answer this question.