如何在 React Native Expo 中将 m3u8 文件转换为 mp4 文件? 我尝试使用 FFmpegKit 将 m3u8 文件转换为 mp4,但出现以下错误:
“无法读取 null 的属性“getLogLevel””和“无法读取 null 的属性“ffmpegSession””
使用此包进行构建也失败(无法确定任务“:ffmpeg-kit-react-native:compileDebugAidl”的依赖关系。)。
React Native Expo中有没有简单易行的方法来转换m3u8文件?
我使用过的代码:
import { FFmpegKit } from 'ffmpeg-kit-react-native';
export async function converterToMp4() {
try {
await FFmpegKit.executeAsync(`-i ${m3u8FileUri} ${mp4FileUri}`)
} catch(err) {
console.log(err)
}
}
我用这个代码得到了它......
const parser = new HLSParser();
parser.push(res);
parser.end();
const pathUri = securityPath(); // This is central function to inform the path
const pathUriM3u8 = securityPath(data?.name, ".m3u8");
const pathUriMp4 = securityPath(data?.name, ".mp4");
const tsUrls: M3u8ParserTypes.Segments[] = parser?.manifest?.segments;
const baseTsFilesUrl = videoUrlPanda.split("/")?.slice(0, -1)?.join("/");
const downloadResumable = FileSystem.createDownloadResumable(videoUrlPanda, pathUriM3u8, {
headers: {
Referer: "some-referer",
},
});
await downloadResumable.downloadAsync();
await Promise.all(
tsUrls.map(async (item) => {
const downloadResumableTsFiles = FileSystem.createDownloadResumable(
`${baseTsFilesUrl}/${item?.uri}`,
pathUri + item?.uri,
{
headers: {
Referer: "some-referer",
},
}
);
await downloadResumableTsFiles.downloadAsync();
})
).catch((err) => {
throw new Error("Failed to download ts files", err);
});
const ffmpegSession = await FFmpegKit.execute(
`-i ${pathUriM3u8} -c:v mpeg4 -y ${pathUriMp4}`
);
await ffmpegSession.getReturnCode();
希望有帮助