const stackVideos = useCallback(
async (video1) => {
try {
console.log("Fetching video2 from storage...");
const video2Ref = ref(storage, "video2.mp4");
const video2Url = await getDownloadURL(video2Ref);
const video2Blob = await (await fetch(video2Url)).blob();
console.log("Writing video1 to FFmpeg FS...");
await ffmpeg.FS("writeFile", "video1.mp4", await fetchFile(video1));
console.log("Writing video2 to FFmpeg FS...");
await ffmpeg.FS("writeFile", "video2.mp4", await fetchFile(video2Blob));
console.log("Files in FFmpeg FS after write:");
const files = await ffmpeg.FS("readdir", "/");
console.log(files);
const { start, end } = inputs[0];
const startSeconds = new Date(`1970-01-01T${start}Z`).getTime() / 1000;
const endSeconds = new Date(`1970-01-01T${end}Z`).getTime() / 1000;
const duration = endSeconds - startSeconds;
console.log("Running FFmpeg command...");
await ffmpeg.run(
"-i",
"video1.mp4",
"-ss",
startSeconds.toString(),
"-t",
duration.toString(),
"-i",
"video2.mp4",
"-filter_complex",
"[0:v]scale=1080:-1[v1];[1:v]scale=-1:1920/2[v2scaled];[v2scaled]crop=1080:1920/2[v2cropped];[v1][v2cropped]vstack=inputs=2,scale=1080:1920[vid]",
"-map",
"[vid]",
"-map",
"0:a",
"-c:v",
"libx264",
"-crf",
"23",
"-preset",
"veryfast",
"-shortest",
"output1.mp4"
);
console.log("Files in FFmpeg FS after run:");
const filesAfterRun = await ffmpeg.FS("readdir", "/");
console.log(filesAfterRun);
console.log("Reading output1.mp4 from FFmpeg FS...");
const data = await ffmpeg.FS("readfile", "output1.mp4");
console.log("after the FS readfile");
const url = URL.createObjectURL(
new Blob([data.buffer], { type: "video/mp4" })
);
setStackedVideo(url);
setOutputFileReady(true); // Mark output file as ready
} catch (err) {
console.error("FFmpeg error output:", err);
setError(`FFmpeg run error: ${err.message}`);
setIsProcessing(false);
}
},
[inputs]
);
My error seems to be stemming from this line:
const data = await ffmpeg.FS("readfile", "output1.mp4");
Seeing the ffmpeg.wasm documentation i thought the functions for some of the functions had changed, but when I changed it, it seemed like they did not recognise the new functions. Sometimes this will also give me some other errors like worker.js which I dont understand enough to debug this myself.
words word words words words words word words words wordswords word words words wordswords word words words wordswords word words words wordswords word words words wordswords word words words words
Paul Tham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.