问题描述
嘿,我正在尝试使用 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}`)
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`;