I am new to ffmpeg and my first post here. what i have and what i want to do is below:

  • I have video, transparent image and .srt file
  • Video with dimension width:1280 Height:720.
  • Transparent image with dimension width:1024 Height:122.
  • .srt file with font sytle stored in html tags.

My goal is to overlay the image with srt text exactly in center and the overlayed image to be exactly in center video.

I started by subtracting the dimension of video with transparent image to position it exactly at center.

ImageX = (video.width - image.width)/2
ImageY = (video.Height - Image.height) * 0.9 (to bottom of video).

After researching i got this code:

ffmpeg.exe -i "C:\Projects\Video Phase 3\Horse\horse.mp4" -i "C:\Projects\Video Phase 3\Horse\Transparent.png" -threads 0 -c:v libx264 -crf 28 -preset veryslow -filter_complex "[0:v][1:v]overlay=128:538:enable='between(t,0,1)', subtitles=C\\:\\\\Projects\\\\Video Phase 3\\\\Horse\\\\ImportedTrack1_0.srt[out]" -map "[out]" -map 0:a "C:\Projects\Video Phase 3\Horse\newout.mp4"

i am able to put the transparent image exactly at center,bottom. But i am not able to position the srt text in image. even if i put the image in Top center, i need to put the text in center of image. Please help me guys

Captured image from out video

  • thanks I will try to force_style, let me see what i get.for the second comment - my project requirement is that users should be allowed to load image at runtime and then text should be overlayed on image and then video . i cannot use drawbox for this. – user3416431 Nov 13 '16 at 7:55
  • i tried the force_style alignment, but it places the srt on top of the video. It would be a manual task to set the alignment everytime. How can i dynamically set the subtitles to place in center middle of the transparent image. – user3416431 Nov 13 '16 at 8:55
  • Try Alignment=10. – llogan Nov 13 '16 at 20:54
  • ok, but how can it be dynamic, say if user changes the font size at runtime – user3416431 Nov 14 '16 at 2:57
  • It should still be centered no matter the font size. – llogan Nov 14 '16 at 3:54

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.