在React Native Expo中将m3u8文件转换为mp4文件

问题描述 投票:0回答:1

如何在 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)
    }
}
react-native video ffmpeg expo ffmpegkit
1个回答
0
投票

我用这个代码得到了它......

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();

希望有帮助

© www.soinside.com 2019 - 2024. All rights reserved.