我正在开发一款应用程序,首先从视频中提取音频,然后将其转录,然后我想将转录的字幕或字幕附加到原始视频中。一切都运行顺利
我正在开发一款应用程序,首先从视频中提取音频,然后将其转录,然后我想将转录的字幕或副标题附加到原始视频中。
一切运行顺利,除了字幕附加部分,如果我直接在终端运行 FFMPEG 命令,它运行良好,但在 Flutter 中却不行
这是我将字幕附加到视频的代码:
Future<void> attachCaptionsToVideo(DeepGramResponse deepGramResponse) async {
var tempDir = await getTemporaryDirectory();
final outputPath = "${tempDir.path}/outputWithCaptions.mp4";
final String subtitlePath = deepGramResponse.captionsPath
.replaceAll('\\', '\\\\')
.replaceAll(' ', '\\ ');
final String command =
'-y -i ${deepGramResponse.videoPath} -vf subtitles=$subtitlePath $outputPath';
await FFmpegKit.executeAsync(command, (session) async {
final returnCode = await session.getReturnCode();
final output = await session.getOutput();
final error = await session.getFailStackTrace();
log('FFmpeg command executed with return code: $returnCode');
if (ReturnCode.isSuccess(returnCode)) {
log('Captions attached successfully');
deepGramResponse.copyWith(
videoPath: outputPath,
);
Get.to(() => VideoPlayerScreen(videoPath: outputPath));
} else {
log('FFmpeg command failed');
log('Error output: $output');
log('Error details: $error');
Fluttertoast.showToast(
msg: 'Something went wrong, please try again later');
}
});
}
这是我得到的错误:
[AVFilterGraph @ 0x7b8a3f35f0] '/data/user/0/com.example.blink/app_flutter/captions.srt' 附近没有选项名称[AVFilterGraph @ 0x7b8a3f35f0] 解析过滤器描述时出错:[AVFilterGraph @ 0x7b8a3f35f0] 解析过滤器链'subtitles=/data/user/0/com.example.blink/app_flutter/captions.srt'时出错:重新初始化过滤器时出错!无法将帧注入过滤器网络:参数无效处理流#0:0的解码数据时出错转换失败!