简体   繁体   中英

Adding subtitles with fluent-ffmpeg

I'm trying to burn in subtitles into a video. This command works perfectly from command line: ffmpeg -i in.mp4 -vf subtitles=sub.srt:force_style='Fontsize=20' out.mp4

My code on server side doesn't seem to do much (it creates test.mp4 though)

ffmpeg('temp/subtitleVideos/qTWVbM5pkKms_pJbE8OAvH3N.mp4')
            .outputOptions(
                '-vf subtitles=temp/subtitleVideos/qTWVbM5pkKms_pJbE8OAvH3N.srt'
            )
            .on('error', function(err) {
                console.log('Error: ' + err.message);
            })
            .save(path + 'test.mp4');

and I get the following error: Error: ffmpeg exited with code 1: Error opening filters!

Ok, I've found our problem. It was incorrect format of .srt file. To compare, this is our incorrect file (=timing is important):

1
00:00:00 --> 00:00:03
kitty cat

2
00:00:03,372 --> 00:00:05,674
is sitting

3
00:00:05,795 --> 00:00:08,905
on a pad

and this one is correct:

1
00:00:00,828 --> 00:00:03,130
kitty cat

2
00:00:03,372 --> 00:00:05,674
is sitting

3
00:00:05,795 --> 00:00:08,905
on a pad

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM