sbis04 / video_trimmer

Flutter video trimmer package
https://pub.dev/packages/video_trimmer
MIT License
431 stars 255 forks source link

Is it possible to add text with custom ffmpeg commands? #11

Closed ThinkSimple closed 3 years ago

ThinkSimple commented 4 years ago

Hey, I'm wondering if it would be possible to insert text inside a video. I tried using the drawtext filter but Im getting the error message "No such filter: 'drawtext'".

sbis04 commented 4 years ago

The error related to drawtext usually occurs if libfreetype library is not present or enabled in the FFmpeg build, according to this StackOverflow post. But I am currently using full FFmpeg, so it should contain this library.

To enable this library, as far as I have understood you have to build FFmpeg from source using the flag --enable-libfreetype. But, I am afraid that I am not sure where to use this flag and I believe that it has to be done natively on Android.

Also, I think it would be better if you can create one issue regarding this in the flutter-ffmpeg package and refer to this issue there, as I am using this package in mine.

sbis04 commented 4 years ago

You have to add the following in the android/build.gradle:

ext.flutterFFmpegPackage = 'full'

So, you won't get the error: "No such filter: 'drawtext'"

Next, you might face an error related to fonts, like this:

E/mobile-ffmpeg(24697): [Parsed_drawtext_0 @ 0x7a7556f4c0] Cannot find a valid font for the family Sans
E/mobile-ffmpeg(24697): [AVFilterGraph @ 0x7a10ac5a80] Error initializing filter 'drawtext'
E/mobile-ffmpeg(24697): [AVFilterGraph @ 0x7a10ac5a80]  with args 'text=Stack Overflow'

For fixing this you have to define a font configuration in my video trimmer package, like this:

final FlutterFFmpegConfig _flutterFFmpegConfig = new FlutterFFmpegConfig();
await _flutterFFmpegConfig.setFontconfigConfigurationPath(<path>);

For more information refer to the Readme here: https://github.com/tanersener/flutter-ffmpeg/tree/master/example

I have not yet tried it out myself. Let me know if you are successful.

ArjanAswal commented 3 years ago

You can add text, as well as an image to the video by using this. I suggest converting the text widget to an image and then adding it to the video because it's more customizable.