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
|
}
|