Flex
2025-06-12 1d29cc7ed2fd9e9f102298fbb08c0f7fe7db50b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { FFmpeg } from "@ffmpeg/ffmpeg";
import { fetchFile, toBlobURL } from "@ffmpeg/util";
 
/* 
    @param  url:文件地址
*/
 
export const MoveToMp4 = async (url:string) => {
    const ffmpegRef = new FFmpeg();
    let messageRef = "";
    const ffmpeg = ffmpegRef;
    await ffmpeg.load({
        // coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"),
        coreURL: await toBlobURL(`/ffmpeg/ffmpeg-core.js`, "text/javascript"),
        wasmURL: await toBlobURL(`/ffmpeg/ffmpeg-core.wasm`, "application/wasm"),
    });
    try {
        ffmpeg.on("log", ({ message }) => {
            messageRef = message;
            console.log(message);
        });
    } catch (error) {
        console.log(error)
    }
    await ffmpeg.writeFile(
        "input.mov",
        await fetchFile(
            url
        )
    );
    await ffmpeg.exec(["-i", "input.mov", "output.mp4"]);
    const data = await ffmpeg.readFile("output.mp4");
    const fileUrl = URL.createObjectURL(
        new Blob([data.buffer], { type: "video/mp4" })
    );
    console.log( fileUrl )
    return fileUrl
}