I'm trying to add a top and bottom section to a video like we do for image memes. I'm using ffmpeg and imagemagick but there is no inbuilt option to do this task. Let's say i have a video and I need to add the caption like this to the whole video. How can i achieve this?
Asked
Active
Viewed 2,697 times
4

Bartłomiej Semańczyk
- 59,234
- 49
- 233
- 358

user1159517
- 5,390
- 8
- 30
- 47
-
What is the format of your video? Do you mean you want to overlay the white writing on top of each frame - you don't want to increase the height of the frame. – Mark Setchell Oct 21 '15 at 10:48
-
2https://www.ffmpeg.org/ffmpeg-filters.html#drawtext-1 – aergistal Oct 21 '15 at 12:26
-
@MarkSetchell Yes, i want to add a white rectangle on top of each frame and write a text on it. – user1159517 Oct 21 '15 at 17:01
1 Answers
10
From what I can tell something like this is what you're looking for:
Using pad and drawtext. In this example pad adds 50 pixels to the top and 50 pixels to the bottom, then two drawtext instances place each line.
ffmpeg -i input -filter_complex \
"[0:v]pad=iw:ih+100:0:(oh-ih)/2:color=white, \
drawtext=text='ONE DOES NOT SIMPLY':fontfile=/path/to/impact.ttf:fontsize=24:x=(w-tw)/2:y=(50-th)/2, \
drawtext=text='STOP ME FROM FILTERING':fontfile=/path/to/impact.ttf:fontsize=24:x=(w-tw)/2:y=h-25-(th/2)" \
output

llogan
- 121,796
- 28
- 232
- 243
-
Hi @LordNeckbeard, 1. "color = white" , how can we change the color, can we pass "#somevalue". 2. "fontfile=/path/to/impact.ttf" is that a built-in ttf file or we are supposed to give some path from assets file as per android. – BST Kaal Nov 20 '15 at 11:18
-
@BSTKaal As for `color` in `pad`, you can use [these color names](https://ffmpeg.org/ffmpeg-utils.html#Color). As for `fontfile` you need to provide the path to the font that you want to use. If your `ffmpeg` build was compiled with `--enable-libfontconfig`, then you can just supply the name as shown in the [fontconfig example](http://ffmpeg.org/ffmpeg-filters.html#Examples-39) (3rd from bottom). Sorry, I know nothing of Android. – llogan Nov 20 '15 at 18:30
-
the command is running, but the output video has only one frame, i.e. the length of video is even less than a sec... – BST Kaal Nov 22 '15 at 07:15
-
Thank you so much @LordNechbeard, I fixed the issue removing `-vframes 1`. – BST Kaal Nov 23 '15 at 04:52