0

Is there way to add a background image under the text on the video in FFmpeg?

I can add black background using 'box', but i need to add some certain image. I tried to use 'drawtext' on a image and then overlayed it on the video, but i don't know text's width and height for scaling the image.

"-i",
"D:/AndroidProjects/Movies/VideoSamples/VideoShort1.mp4",
"-i",
"D:/AndroidProjects/Movies/ImageSamples/SampleImage.jpeg",
"-filter_complex",
"[0:v]drawtext=text='Example':fontcolor=#DB7093:fontsize=120:box=1:[email protected]:boxborderw=5:x='(w/2) - (tw/2)':y='h - ((h/2) - (th/2))",
"-s",
"1280x720",
"-y",
"D:/AndroidProjects/Movies/FFmpegSampleShort0.mp4"

I expect to get video with some image background under my text instead black color. Final video

1 Answer 1

0

I found only one solution for this case, but we have to create one dummy video and don't forget to delete him. In total this solution contains two actions but i didn't found any another.

  1. Draw you text on some video or dummy(black empty video) and add command for println to console text width and height when we use filter complex. For example:
"-i",
"D:/AndroidProjects/Movies/VideoSamples/VideoShort1.mp4",
"-filter_complex",
"drawtext=SomeText:x='print(tw) * 0 + 0 * print(th)'"
"-y",
"D:/AndroidProjects/Movies/TemporaryVideoForScaleText.mp4"
  1. Get string console output and found with regex value of your texts size.
  2. Now you know your text sizes and you can to scale your image under your text for new ffmpeg command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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