Adding caption to GIF/video/multiple images using FFMPEG

Oct 15, 2020 23:09

So, I came across this situation where I want to add some caption to my gif at certain scenes (not entire gif). Normally I will prepare subtitle file, burn in the video and then I'll start making the gif. But this is too much of hassle. So after soo much try-and-error, I figures this method suits me well.

1. Let's dissecting the video into images 1st.
Command: ffmpeg -i input.mp4 -vf scale=480:-1 -qscale 0 a%d.jpg
Result: You'll get multiple images from the video frames.


2. Based on result in 1st, you'll get the images' filename as follows: a1.jpg, a2.jpg etc. Ensure that if you want to bulk caption these images, the name must be in sequence.


3. Put the caption.
Command: ffmpeg -i "a (%d).jpg" -vf drawtext="fontfile=C\\:/Windows/Fonts/COOPBL.TTF:fontsize=30:fontcolor=white:box=1:boxcolor=black@1.0:x=(w-text_w)/2:y=(h-30):text='He said it!'" -qscale 0 "b (%d).jpg"
Basically you can manipulate the font you want to use, the fontcolor and fontsize and you can decide whether you want to have box in the background of your caption or not and lastly, the position where to put the caption.
For the command above, here's the result:


Command: ffmpeg -i "a (%d).jpg" -vf drawtext="fontfile=C\\:/Windows/Fonts/HARLOWSI.TTF:fontsize=30:fontcolor=white:x=(w-text_w)/2:y=(h-30):text='He said it!'" -qscale 0 "b (%d).jpg"
For this command, I removed the box behind the caption and change the font.


Command: ffmpeg -i "a (%d).jpg" -vf drawtext="fontfile=Bismillah Script.otf:fontsize=50:fontcolor=0xD2691E:x=(w-text_w)/2:y=(h-text_h)/2:text='He said it!'" -qscale 0 "b (%d).jpg"
For this command, I changed the font (notice that there is no "C\\:/Windows/Fonts/ anymore, this is because I copy the font to the source folder where the images located), changed the fontsize and color and also changed the location of the caption.


I haven't fully grasp on how to manipulate the caption coordinate...

ffmpeg: gif, ffmpeg: caption, ffmpeg: subtitle, ffmpeg: hardsub, ffmpeg: image

Previous post Next post
Up