skip to Main Content

I’m using AWS lambda with python and ffmpeg to add textual watermark over images. I added a custom font i.e Quicksand to my lambda function like this:

1- Create a fonts directory in the root of the function and add the font file (.ttf) and a font.conf file with the following contents:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <dir>/var/task/fonts/</dir>
  <cachedir>/tmp/fonts-cache/</cachedir>
  <config></config>
</fontconfig>

2- Added an environment variable like this

FONTCONFIG_PATH = "/var/task/fonts"

It was working fine until I chose to add more fonts. Now when I try to use some font other than the Quicksand e.g Arial, it still uses the Quicksand font. I’m not sure why? In the CloudWatch Logs I can see it is still trying to access the Quicksand font rather than the Arial one even when the code is right. Any caching issue or something else?

My folder structure:
enter image description here

Cloudwatch logs:

[Parsed_drawtext_0 @ 0x70b5bc0] Using "/var/task/fonts/Quicksand.ttf"

Maybe its a caching issue? I’m not sure.

My ffmpeg code:

ffmpeg -i video.mp4 -vf "drawtext=font=‘Quicksand.ttf'
:text='StackOverflow':fontcolor=white:fontsize=24:box=1:[email protected]:boxborderw=5:x=w-mod(max(t-0,0)*(w+tw)/6,(w+tw)):y=(h-text_h)/2" -codec:a copy Newwwtext.mp4

2

Answers


  1. Chosen as BEST ANSWER

    Following @Luiz Correia advice, I ended up using s3 bucket to store the font files. Inside my lambda function I copied the font file from s3 bucket to the /tmp directory and then used it inside the ffmpeg command. I also updated the ffmpeg command to use fontfile instead of font inside drawtext, like this:

    ffmpeg -i video.mp4 -vf "drawtext=fontfile=‘Quicksand.ttf'
    :text='StackOverflow':fontcolor=white:fontsize=24:box=1:[email protected]:boxborderw=5:x=w-mod(max(t-0,0)*(w+tw)/6,(w+tw)):y=(h-text_h)/2" -codec:a copy Newwwtext.mp4
    

  2. you need be more specific about where your files are.

    And how many times your lambda run.
    I think the best solution was using the S3 or the EFS.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search