微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 ReactNative 中使用 ffmpeg concat 获取此错误“无法打开连接”

如何解决在 ReactNative 中使用 ffmpeg concat 获取此错误“无法打开连接”

嘿,我正在尝试使用 ffmpeg concat 连接多个视频,在 samsung j76、android 版本 8.1.0 上进行测试

const textFile = await (await writeTextFileWithAllVideoFiles(filePaths))  
const outputPath = Platform.OS === 'ios' ? `${RNFS.DocumentDirectoryPath}/video-1.mp4` : `${RNFS.DocumentDirectoryPath}/video-1.mp4`
console.log(`-f concat -safe 0 -i ${textFile} -c copy ${outputPath}`)
const result = await RNFFmpeg.execute(`-f concat -safe 0 -i ${textFile} -c copy ${outputPath}`)

这是我创建txt文件方法

const writeTextFileWithAllVideoFiles = async (filePaths) => {
var RNFS = require('react-native-fs');
var path = RNFS.DocumentDirectoryPath + '/videoList.txt';

var fileContent = ''
console.log("fileplay1");
filePaths.forEach(path => {
   fileContent += 'file ' + '\'' + path.substring(8) + '\'' + '\r\n'
});
console.log(fileContent);
return RNFS.writeFile(path,fileContent,'utf8')
.then((success) => {
   console.log(path)
   if (RNFS.exists(path))
      console.log('FILE WRITTEN!')
   return path
})
.catch((err) => {
    console.log(err.message)
    return err.message
});  
}

这是我的控制台日志输出

file 'data/user/0/com.videoeditorapp/cache/Camera/f27579d2-1488-4a59-8a9d-7a4e7b6fe716.mp4'
file 'data/user/0/com.videoeditorapp/cache/Camera/58130175-bd20-4002-9629-070d0cdd18ac.mp4'

[Tue Feb 02 2021 16:30:45.375]  LOG      /data/user/0/com.videoeditorapp/files/videoList.txt
[Tue Feb 02 2021 16:30:45.376]  LOG      FILE WRITTEN!
[Tue Feb 02 2021 16:30:45.376]  LOG      -f concat -safe 0 -i /data/user/0/com.videoeditorapp/files/videoList.txt -c copy /data/user/0/com.videoeditorapp/files/video-1.mp4
[Tue Feb 02 2021 16:30:45.376]  LOG      [concat @ 0xe2b22000] Impossible to open '/data/user/0/com.videoeditorapp/files/data/user/0/com.videoeditorapp/cache/Camera/f27579d2-1488-4a59-8a9d-7a4e7b6fe716.mp4'
[Tue Feb 02 2021 16:30:45.377]  LOG      /data/user/0/com.videoeditorapp/files/videoList.txt: No such file or directory

并且 txt 文件不在我的 android 设备上 我的清单是这样的

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
      

<application android:requestLegacyExternalStorage="true" ... />

解决方法

我没有看到该文本文件将其路径添加到我在 txt 文件中的路径 /data/user/0/com.videoeditorapp/files/data/user/0/com。 videoeditorapp/cache/Camera/f27579d2-1488-4a59-8a9d-7a4e7b6fe716.mp4

我把它改成

var path = 'data/user/0/com.videoeditorapp/cache/Camera/videoList.txt';

这就是

const arr = path.split('/');    
fileContent += `file '${arr[arr.length - 1]}'\r\n`;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。