I’m running a flutter app with Ffmpeg-kit package to burn a subtitle on a video. i have a words list with the timings and map that to generate an srt and ass file. but when executing this tho it didn’t work.
first here is how i generated the Ass file.
Future<String> _createAssFile() async {
String filePath = await getAssOutputFilePath();
final file = File(filePath);
final buffer = StringBuffer();
// Write ASS headers
buffer.writeln('[Script Info]');
buffer.writeln('Title: Generated ASS');
buffer.writeln('ScriptType: v4.00+');
buffer.writeln('Collisions: Normal');
buffer.writeln('PlayDepth: 0');
buffer.writeln('Timer: 100,0000');
buffer.writeln('[V4+ Styles]');
buffer.writeln(
'Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding');
buffer.writeln(
'Style: Default,Arial,40,&H00FFFFFF,&H000000FF,&H00000000,&H80000000,1,1,1,1,100,100,0,0,1,1,1,2,10,10,10,1');
buffer.writeln('[Events]');
buffer.writeln(
'Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text');
// Write events (subtitles)
for (int i = 0; i < widget.words.length; i++) {
final word = widget.words[i];
final startTime = _formatAssTime(word['startTime'].toDouble());
final endTime = _formatAssTime(word['endTime'].toDouble());
final text = word['word'];
buffer.writeln('Dialogue: 0,$startTime,$endTime,Default,,0,0,0,,$text');
}
await file.writeAsString(buffer.toString());
return filePath;
}
String _formatAssTime(double seconds) {
final int hours = seconds ~/ 3600;
final int minutes = ((seconds % 3600) ~/ 60);
final int secs = (seconds % 60).toInt();
final int millis = ((seconds - secs) * 1000).toInt() % 1000;
return '${hours.toString().padLeft(1, '0')}:${minutes.toString().padLeft(2, '0')}:${secs.toString().padLeft(2, '0')}.${(millis ~/ 10).toString().padLeft(2, '0')}';
}
then i used this command which was the official way of adding ass file to a video.
String newCmd = "-i $videoPath -vf ass=$assFilePath -c:a copy $_outputPath";
yet when executing this command it did not work. However i changed it to this command
String newCmd = "-i $videoPath -i $assFilePath $_outputPath";
well that code works but the styling is not being applied. so i tried yet another command to filter and position the ass file.
String newCmd = "-i $videoPath -i $assFilePath -filter_complex "[0:v][1:s]ass=\an5:text='%{event.text}',scale=iw*0.8:ih*0.8,setdar=16/9[outv]" -map [outv] -c:a copy $_outputPath";
well this even made it worse. coz the app crashed when i run this. also there is a log for this command before crashing
F/libc (19624): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x19 in tid 21314 (pool-4-thread-7), pid 19624 (ple.caption_app)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/a15nsxx/a15:14/UP1A.231005.007/A155FXXU1AWKA:user/release-keys'
Revision: '5'
ABI: 'arm64'
Processor: '7'
Timestamp: 2024-07-10 19:27:40.812476860+0300
Process uptime: 1746s
Cmdline: com.example.caption_app
pid: 19624, tid: 21314, name: pool-4-thread-7 >>> com.example.caption_app <<<
uid: 10377
tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000019
Cause: null pointer dereference
x0 0000000000000001 x1 b400006ec98d8660 x2 0000000000000000 x3 0000000000000002
x4 0000006f62d1ea12 x5 b400006e04f745ea x6 352f35372f64352f x7 7f7f7f7f7f7f7f7f
x8 632ace36577a905e x9 632ace36577a905e x10 0000006e191378c0 x11 0000000000000001
x12 0000000000000001 x13 0000000000000000 x14 0000000000000004 x15 0000000000000008
x16 0000006e27ffa358 x17 0000006e27dbfb00 x18 0000006e00d48000 x19 0000006f62d1f0e8
x20 0000006f62d24000 x21 0000006e27ffc5d0 x22 0000006e27ffc5f0 x23 0000000000000000
x24 b400006f3f089248 x25 0000006f62d1f220 x26 b400006f3f057b20 x27 0000000000000002
x28 0000000000000088 x29 0000006f62d1f100
lr 0000006e27dbfb0c sp 0000006f62d1f0a0 pc 0000006e27dbfb10 pst 0000000060001000
1 total frames
backtrace:
#00 pc 0000000000121b10 /data/app/~~oWqjrGA2indQhuEw6u_J2A==/com.example.caption_app-u2Ofk54FVtMc5D-i3SLC6g==/base.apk!libavfilter.so (offset 0x10a46000) (avfilter_inout_free+16)
Lost connection to device.
i tried the normal command in my local machine on windows. and this is what i used
ffmpeg -i F:ffmpegvideo.avi -vf subtitles='F:\ffmpeg\caption.srt':force_style='Fontsize=24' F:ffmpegnew.mp4
as you can see above when subtitles are used it had an extra backslashes for each path and a pre backslash after the partition letter. but i don’t know if this does apply for android devices. so can u help me make sense of this and provide me with the correct way to do it?