im not able to load ffmpeg as i tried everything im using nextjs with turbopack and its not working so diasable turbopack still its persist #837
Unanswered
swappy-2003
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
this is my code i have project submission on 15 th feb help me
"```
use client";
import { useEffect, useState, useRef } from "react";
import SparklesIcon from "@/components/sparklesIcon";
// Import FFmpeg constructor and utilities from @FFmpeg packages
import { FFmpeg } from "@ffmpeg/ffmpeg";
import { fetchFile } from "@ffmpeg/util";
export default function ResultVideo({ filename }) {
// State to track whether FFmpeg is loaded
const [loaded, setLoaded] = useState(false);
// State to hold the transcoded video Blob URL
const [transcodedVideoUrl, setTranscodedVideoUrl] = useState(null);
// Create an instance of FFmpeg using the constructor directly
const ffmpegRef = useRef(new FFmpeg());
// Refs for the video element and a log message container
const videoRef = useRef(null);
const messageRef = useRef(null);
useEffect(() => {
if (!filename) return;
}, [filename]);
// Function to transcode a video once FFmpeg is loaded
const transcode = async () => {
if (!loaded) {
console.error("FFmpeg is not loaded yet");
return;
}
const ffmpeg = ffmpegRef.current;
try {
console.log("Starting transcoding...");
// For demonstration, we use a test video file.
const inputUrl =
"https://raw.githubusercontent.com/ffmpegwasm/testdata/master/Big_Buck_Bunny_180_10s.webm";
// Download and write the input file to FFmpeg's in-memory filesystem
await ffmpeg.writeFile("input.webm", await fetchFile(inputUrl));
// Execute FFmpeg command to convert webm to mp4
await ffmpeg.exec(["-i", "input.webm", "output.mp4"]);
// Read the transcoded output file
const data = await ffmpeg.readFile("output.mp4");
// Create a Blob URL from the transcoded data
const url = URL.createObjectURL(
new Blob([data.buffer], { type: "video/mp4" })
);
setTranscodedVideoUrl(url);
console.log("Video transcoded successfully");
} catch (error) {
console.error("Error during transcoding:", error);
}
};
return (
Original Video
<video
ref={videoRef}
controls
style={{ width: "100%", maxWidth: "600px" }}
>
{transcodedVideoUrl && (
Transcoded Video:
<video
src={transcodedVideoUrl}
controls
style={{ width: "100%", maxWidth: "600px" }}
>
)}
<div style={{ textAlign: "center", marginTop: "1rem" }}>
<button
onClick={transcode}
disabled={!loaded}
style={{
padding: "0.5rem 1rem",
backgroundColor: loaded ? "#38a169" : "#a0aec0",
color: "white",
border: "none",
borderRadius: "9999px",
cursor: loaded ? "pointer" : "not-allowed",
}}
>
Apply Captions
<p ref={messageRef} style={{ marginTop: "1rem" }}>
Open Developer Tools (Ctrl+Shift+I) to view logs
);
}
Beta Was this translation helpful? Give feedback.
All reactions