3

I am creating a video with FFmpeg library. I want access fonts from Android assets folder and overlay on my video as watermark.

What is the path for Android assets folder to access and apply custom font on FFmpeg? I can overlay watermark on video but when I try to apply custom font on it, it gives error related to not exist, etc.

What I found till now:

The alternative solution that I found is the create an image file and write text on it and overlay image on video. problem is text and image being stretch output. I need a solution for it.

String[] execute = {"-y",  "-i",  videoPath, "-i", image, "-filter_complex",
             "[1:v]scale=" + width + ":" + height + "[ovrl],[0:v][ovrl]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2"
             ,"-strict" , "experimental", "-vcodec", "libx264" , "-preset",  "ultrafast" , "-crf",  "20", "-acodec",  "aac",  "-ar",
             "44100",  "-ac",  "2",  "-b:v",  "36000k",   outputPath.getPath()};

I thought itz output will be good but it stretching my text and image.

I want some perfect solution to apply assets font on FFmpeg.

Thank you in Advance.

Community
  • 1
  • 1
Dens
  • 125
  • 11
  • can you share you image which you pass a input – Vinesh Chauhan Aug 07 '19 at 09:10
  • it is transparent image. i have to show some text as well as stickler. so when i capture video at that time i create transparent image and draw text over it later i will show image preview with video and add sticker on it i want to. and if add sticker then i have create another transparent bitmap and draw sticker on it and for result combine those 2 image in one image and use to create video – Dens Aug 07 '19 at 09:26
  • from above process my sticker and text stretched. – Dens Aug 07 '19 at 09:33

1 Answers1

7

Assets Directry is nt directly accessible by FFMPEG you have to copy that in internal storage then you can pass t to ffmpeg otherwise ffmpeg troughs error ffmpeg is native library for vdeo editing so it can fetch assets data

You can use drawtext attribute to draw text on Image/ Video. Drawtext has its own parameter for fontstyle here is a simple example code how to draw text on video/image with custom fontstyel and color

ffmpeg -i input.mp4 -filter_complex "drawtext=text=Vinesh Chauhan:fontcolor=#000000:fontsize=14:x=43:y=103:fontfile=FACEBOLF.OTF" -y output.mp4

here

text= what you want to draw as text on video/image

fontcolor = color for font

fontsize = fontsize for your text

x and y is used to draw your text on specified co-ordinates

fontfile= pass you fontsyle file(TTF) file path

if you wish to add image as water mark on video do not scale tahat image otherwise it alter the image aspec ratio

use below code that not alter width height of image

String[] execute = {"-y",  "-i",  videoPath, "-i", image, "-filter_complex",
             "[1:v]scale=iw:-2[ovrl],[0:v][ovrl]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2"
             ,"-strict" , "experimental", "-vcodec", "libx264" , "-preset",  "ultrafast" , "-crf",  "20", "-acodec",  "aac",  "-ar",
             "44100",  "-ac",  "2",  "-b:v",  "36000k",   outputPath.getPath()};

or your app has custom height width functionality so use below code that will maintain your aspect ratio

String[] execute = {"-y",  "-i",  videoPath, "-i", image, "-filter_complex",
             "[1:v]scale=" + width + ":-2[ovrl],[0:v][ovrl]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2"
             ,"-strict" , "experimental", "-vcodec", "libx264" , "-preset",  "ultrafast" , "-crf",  "20", "-acodec",  "aac",  "-ar",
             "44100",  "-ac",  "2",  "-b:v",  "36000k",   outputPath.getPath()};
Vinesh Chauhan
  • 1,288
  • 11
  • 27