【问题标题】:Appending two audiofiles React Native附加两个音频文件 React Native
【发布时间】:2020-04-21 10:03:11
【问题描述】:

我想将 wav 文件合并为一个文件。所以文件 1 + 文件 2 = 文件 3。 我目前正在研究 ffmpeg,但是当我尝试使用 concat 时,它只返回一个具有第一个文件长度的文件。我使用的反应原生代码是:

RNFFmpeg.execute('-i "concat:' + path1 + '|' + pathOutput + '" -acodec copy ' + pathOutput2).then(result => console.log("FFmpeg process exited with rc " + result.rc)); 

我的命令错了吗?

如果您对此有更好的解决方案,请告诉我!

【问题讨论】:

    标签: react-native audio ffmpeg concat


    【解决方案1】:

    Ffmpeg concat 协议不适用于 mp4 文件。它只返回第一个文件。 Concat demuxer 完美地完成了这项工作。

    下面是工作代码:

    export const mergeAllRecordingsForVisit = async (filePaths) => {
      const textFile = await writeTextFileWithAllAudioFiles(filePaths)
      const outputPath = 'finalRecording.mp4'
      const command = `-f concat -safe 0 -i ${textFile} -c copy ${outputPath}`
      const result = await RNFFmpeg.execute(command)
    }
    
    
    const writeTextFileWithAllAudioFiles = async (filePaths) => {
      var fileContent = ''
      filePaths.forEach(path => {
        fileContent += `file '${path}'\n`
      });
      const filePath = 'audioList.txt'
      try {
        await RNFS.writeFile(filePath, fileContent, 'utf8')
        return filePath
      } catch (error) {
        return error
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2021-05-15
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      相关资源
      最近更新 更多