在 Flutter 中使用 ffmpeg 添加文本到视频

问题描述 投票:0回答:1

我正在尝试使用 ffmpeg 包向视频添加文本,但它返回错误,即返回代码 1 这是我的代码。

  final videoPath = _controller.file.path;
  final outputName = videoPath.hashCode.toString();

  final output =
        File('${(await getTemporaryDirectory()).path}/$outputName.mp4');

  String command =
        "-y -i $videoPath -filter_complex '[0]scale=540:-1[s];[s]drawtext=fontfile=/storage/emulated/0/Download/SuperDessert.ttf:text='MY_TEXT':fontsize=24:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2' ${output.path}";

  final session = await FFmpegKit.execute(command);

  final returnCode = await session.getReturnCode();

  if (ReturnCode.isSuccess(returnCode)) {
    log("Success full text added");
  } else {
    log("Error adding text: ${await session.getFailStackTrace()}");
  }

我尝试更改输出目录,将

fontfile
更改为
font

flutter dart ffmpeg
1个回答
0
投票

每当您使用字体而不是默认字体时,请使用 FFmpegKitConfig.setFontDirectoryList 函数。

FFmpegKitConfig.setFontDirectoryList(["/system/fonts", "/System/Library/Fonts", "<folder with fonts>"]);
© www.soinside.com 2019 - 2024. All rights reserved.