简体   繁体   English

使用 fluent-ffmpeg 添加字幕

[英]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此命令从命令行完美运行: 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)我在服务器端的代码似乎没有做太多(虽然它创建了 test.mp4)

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!我收到以下错误: Error: ffmpeg exited with code 1: Error opening filters!

Ok, I've found our problem.好的,我找到了我们的问题。 It was incorrect format of .srt file. .srt文件格式不正确。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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