FFMPEG Command to add text to a image
Solution 1
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
.
Solution 2
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
Solution 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
Related videos on Youtube
Paba
Updated on June 06, 2022Comments
-
Paba about 2 years
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.
-
Paba almost 13 yearsI need some library to do this. Annotation needs to happen automatically through my tool.
-
Orbling almost 13 years@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.
-
Paba almost 13 yearsthanx 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 ?
-
Orbling almost 13 years
-
Paba almost 13 yearsThanx Orbling, can you provide me with a link to the Debian package ?
-
Orbling almost 13 years@Kumaripaba: The general page for the package is: packages.debian.org/sid/imagemagick at the bottom you can pick your architecture for a binary. Myself, I would just retrieve it with the package manager, that is why I did not provide a link previously.
-
Paba almost 13 yearsthanx again Orgling, I downloaded the AMD64 architecture as it suits my system. But im kind of new to debian linux. how do i install this *.db file ? I also tried sudo aptitude install imagemagic command and it worked.but when i try " convert -size 320x240 xc:lightblue -pointsize 72 -fill blue -annotate +25+70 'Anthony' anthony.JPEG" im getting errors. But my installation in windows works perfectly. do you have any suggestions ? Thanx in advance.
-
Orbling almost 13 years@Kumaripaba: Does the program run at all? What happens when you type just
convert
at the command line? -
Paba almost 13 yearsThe convert command give me the list of options. Given below is the error im getting when the entire text typing command is entered.
-
Paba almost 13 yearsconvert: delegate library support not built-in
/usr/share/fonts/type1/gsfonts/n019003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/1513. convert: no decode delegate for this image format
/tmp/magick-0pypuC0z-00000001' @ error/constitute.c/ReadImage/532. convert: Postscript delegate failed `/tmp/magick-T8jAxDqo': @ error/ps.c/ReadPSImage/807. -
Paba almost 13 yearsconvert: no decode delegate for this image format
/tmp/magick--m6TlS55-00000001' @ error/constitute.c/ReadImage/532. convert: Postscript delegate failed
/tmp/magick-nSSCZibp': @ error/ps.c/ReadPSImage/807. convert: no encode delegate for this image format `black2.JPEG' @ error/constitute.c/WriteImage/1193. -
Orbling almost 13 years@Kumaripaba: Are you trying to convert postscript at some stage? IM uses some delegate programs, externals, to achieve certain tasks, for postscript rendering it uses ghostscript. Check that you have that installed.
-
Paba almost 13 yearsI only tried the convert command i entered in the former comment. this is the output i get when i type ghostscript
-
Paba almost 13 yearsGPL Ghostscript 8.62 (2008-02-29) Copyright (C) 2008 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. GPL Ghostscript GPL Ghostscript 8.628.62: : Cannot open X display
(null)'. Cannot open X display
(null)'. **** Unable to open the initial device, quitting. -
Orbling almost 13 years@Kumaripaba: That's fine. I wonder if you have the freetype and jpeg libraries installed. When you installed
imagemagick
package, did you tell it to do dependencies? It should do all that automatically. Tryconvert -list delegate | grep ps
to see what postscript related delegates are used by the system. It sounds like a freetype issue to me though, this thread might be of use, particularly the last post. -
Paba almost 13 yearsnow I'm a little bit confused, can you tell me how tell it to install all the dependencies ? I typed the convert -list delegate | grep ps command and in that list i do not see jpeg or freetype. can you please tell me how to solve it ?
-
Orbling almost 13 years@Kumaripaba: jpeg and freetype should not show up there, the
| grep ps
bit just focusses on the postscript parts, amongst others in that list, as the error you are getting is apparently some sort of postscript delegate issue. Though that link I provided you with to the thread had a similar issue and was due to a linkage issue with the wrong freetype library. Might be an idea to compile imagemagick from source, with the--without-x
option, to switch off support for X-Windows, if you are using the server by command line only. -
Paba almost 13 yearsnow i tried the instructions in imagemagick.org/script/install-source.php#unix. I only altered ./configure as ./configure --without-x. This time the testing command "/usr/local/bin/convert logo: logo.gif" worked.but the command convert -size 320x240 xc:lightblue -pointsize 72 -fill blue -annotate +25+70 'Anthony' black2.JPEG gave errors. When i changed black2.JPEG to black2.gif it still gave errors but created the .gif image without text. given below are the errors i got
-
Paba almost 13 yearsconvert: delegate library support not built-in
/usr/share/fonts/type1/gsfonts/n019003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/1513. convert: no decode delegate for this image format
/tmp/magick-0sDmqEId-00000001' @ error/constitute.c/ReadImage/532. convert: Postscript delegate failed/tmp/magick-4QDVhaED': @ error/ps.c/ReadPSImage/807. convert: delegate library support not built-in
/usr/share/fonts/type1/gsfonts/n019003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/1513. -
Paba almost 13 yearsconvert: no decode delegate for this image format
/tmp/magick-i1dk2qzx-00000001' @ error/constitute.c/ReadImage/532.convert: Postscript delegate failed
/tmp/magick-HNyUQm8N': @ error/ps.c/ReadPSImage/807. convert: no encode delegate for this image format `black.JPEG' @ error/constitute.c/WriteImage/1193. -
Orbling almost 13 years@Kumaripaba: If the GIF worked, the text did not, and the JPEG did not. Then I would say there is an issue with the jpeg library and the freetype library. Either not installed properly or not linked. Did you look at the output from the
./configure
process? Did it find the libraries it needed? -
Lasse V. Karlsen almost 13 yearsPlease edit the relevant portions of the above comments into either the question or the answer. Comments are for short feedback-like messages, not for carrying on discussions related to the questions/answers.
-
Orbling almost 13 years@Lasse V. Karlsen: I would've taken this to chat long ago, but the OP does not have sufficient reputation to do so, even though the message sits there telling us to switch this in to chat. This discussion is a spinoff from the question, but not the question itself, this is what private chat is for on here, but denied - an issue for meta?
-
Lasse V. Karlsen almost 13 yearsDefinitely an issue for meta. But, isn't the rep level requirement 20 for chat?
-
Orbling almost 13 years@Lasse V. Karlsen: I think it counts as a gallery chat room, it being private, which has a 1,000 reputation cap. :-/
-
Shubham AgaRwal almost 6 yearsOption 'drawtext' not found, Error initializing filter 'scale' with args '-1:480:drawtext=text=Test any comment on this
-
Agey about 5 yearsThis command worked flawlessly for me. Maybe you are missing a library if you compiled it yourself?
-
Mint over 2 yearsIf 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
withffmpeg
to preserve quality. Just my 2c