flutter 音频修剪

标签 flutter dart audio ffmpeg trim

我修剪音频。使用以下代码。
我在 https://pub.dev/packages/audiocutter 中找到代码包裹。
但无法生成输出文件。

import 'package:path_provider/path_provider.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';

static Future<String> cutAudio(String path, double start, double end) async {
    
    final Directory dir = await getTemporaryDirectory();
    final outPath = "${dir.path}/output.mp3";
    var cmd = "-y -i \"$path\" -vn -ss $start -to $end -ar 16k -ac 2 -b:a 96k -acodec libmp3lame $outPath";
    log(cmd);

    FFmpegKit.executeAsync(cmd, (session) async {
      final returnCode = await session.getReturnCode();

      print("returnCode $returnCode");
    });

    return outPath;
}
请帮助我如何修剪音频。

最佳答案

我收到此错误是因为输出文件已经存在。
所以我使用删除现有文件解决了这个问题。
我使用以下代码删除了文件。

try {
  await File(outPath).delete();
} catch (e) {
  print("Delete Error");
}
以下是我的工作代码。
static Future<String> cutAudio(String path, double start, double end) async {
        
        final Directory dir = await getTemporaryDirectory();
        final outPath = "${dir.path}/output.mp3";
    
        try {
          await File(outPath).delete();
        } catch (e) {
          print("Delete Error");
        }
    
        var cmd = "-y -i \"$path\" -vn -ss $start -to $end -ar 16k -ac 2 -b:a 96k -acodec libmp3lame $outPath";
        log(cmd);
    
        FFmpegKit.executeAsync(cmd, (session) async {
          final returnCode = await session.getReturnCode();
    
          print("returnCode $returnCode");
        });
    
        return outPath;
    }

关于 flutter 音频修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70241682/

相关文章:

android - Flutter 范围错误 : Invalid value: . ...,包括:-1

dart - 多个小部件使用相同的 GlobalKey

button - 如何制作 “on-off”音乐按钮?

flutter - 如何在 Flutter 中检测手机震动

Flutter - 列内扩展小部件内的文本溢出

dart - 调用 setState 后如何防止 Flutter 应用滚动到顶部?

audio - 查找视频文件中是否有音频

flutter - 我想知道用户是否已经对我的应用进行了评价?

dart - 如何将重复的嵌套模板绑定(bind)到复杂模型

javascript - 在 HTML/Javascript 中播放随机音频