8

I need to create a video with a set of images and I successfully did this with ffmpeg. now i need a way to add credits to the singer and video creator. This is part of the work involved in the video creation tool im implementing. Can someone tell me how to add text to an image with ffmpeg.

Thanks in advance.

3 Answers 3

10
ffmpeg -i input.jpg -vf "drawtext=text='Test Text':fontcolor=white:fontsize=75:x=1002:y=100:" output.jpg

this code will write Test Text to the input.jpg and you will get it as output.jpg with text on it

2
  • Option 'drawtext' not found, Error initializing filter 'scale' with args '-1:480:drawtext=text=Test any comment on this Commented Jul 23, 2018 at 12:23
  • This command worked flawlessly for me. Maybe you are missing a library if you compiled it yourself?
    – Agey
    Commented May 23, 2019 at 15:24
3

if you are using ffmpeg you can do this using drawtext filter;

I have added local Time on video with text TEST - prefix and black box as background with 0.7 opacity, you can add more parameters like font size etc as well;

ffmpeg -i input.mp4 -vf "drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text='TEST- %{localtime\:%T}': fontcolor=white:box=1:[email protected]: x=70: y=400" -y output.mp4

2

If you already have the images, it will probably be most sensible to do such annotations directly to the images using Image Magick.

Take a look at the -draw for text and -annotate operators on convert.

26
  • I need some library to do this. Annotation needs to happen automatically through my tool.
    – Paba
    Commented Jul 15, 2011 at 8:14
  • 1
    @Kumaripaba: There are API libraries for most major languages, some are wrappers for the command line tools, others linked to native code. Alternatively, just use the command line tools directly. As you did not specify what language your tool uses, I can not recommend anything.
    – Orbling
    Commented Jul 15, 2011 at 9:35
  • thanx for the comment. I'm working with java but i thought of using the command line tool. im developing my tool as a web app. So my server is linux debian. do you know whether there's a binary for this os ? or do i have to install it from the source ?
    – Paba
    Commented Jul 15, 2011 at 10:24
  • @Kumaripaba: There is a Debian package called imagemagick, just do an install with dependencies for that package to get the command lines available machine-wide. There are two Java-based interfaces, jmagick which is JNI-based and im4java which is pure-java. Might be worth checking those out.
    – Orbling
    Commented Jul 15, 2011 at 11:43
  • 1
    If you're working with large images I'd recommend staying away from ImageMagick (or GraphicsMagick), both are slow (though gm is faster, out of the two). I'd stick with doing it in ffmpeg if at all possible, it's orders of magnitude faster at processing large images, adding text etc. But I'd rec using -qscale:v 2 with ffmpeg to preserve quality. Just my 2c
    – Mint
    Commented Jan 11, 2022 at 10:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.