Summary of the problem: I’m developing a video processing feature in a React application that uses Firebase as the backend. The video file uploads to Firebase Storage without issues. However, when attempting to use FFmpeg to extract the audio as a FLAC file, the process works for videos under an hour but fails for longer videos, producing the error: “Error: File could not be read! Code=-1”.
Code context: The issue occurs during the process of grabbing the video URL from Firebase Storage and extracting audio using FFmpeg. Here is the code snippet:
try {
const videoDownloadURL = await getDownloadURL(uploadTask.snapshot.ref);
console.log('Video file available at', videoDownloadURL);
await ffmpeg.load();
await ffmpeg.writeFile(file.name, await fetchFile(file));
await ffmpeg.exec(['-i', file.name, '-q:a', '0', '-map', 'a', '-ac', '1', 'output.flac']); // Ensuring mono channel
const audioData = await ffmpeg.readFile('output.flac');
const audioBlob = new Blob([audioData.buffer], { type: 'audio/flac' });
const audioStorageRef = ref(storage, `${user.uid}/${videoId}.flac`);
const audioUploadTask = uploadBytesResumable(audioStorageRef, audioBlob, {
contentType: 'audio/flac',
customMetadata: {
uploadedBy: user.uid,
videoId: videoId
}
});
audioUploadTask.on('state_changed',
(snapshot) => {
const audioProgress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100 * 0.1);
setUploadProgress(Math.round(videoProgress + audioProgress));
console.log(`Audio upload progress: ${Math.round(audioProgress)}%`);
},
(error) => {
console.error("Audio upload error:", error);
},
async () => {
try {
const audioDownloadURL = await getDownloadURL(audioUploadTask.snapshot.ref);
console.log('Audio file available at', audioDownloadURL);
audioUploadComplete = true;
} catch (error) {
console.error("Audio download URL error:", error);
}
}
);
} catch (error) { console.error("Download URL error:", error); }
Issue description: The above code successfully extracts audio from videos shorter than one hour. However, for videos around two to three hours long, the code breaks with the following error message:
error code
I suspect this might be related to FFmpeg or Firebase’s handling of larger files, but I’m not sure how to debug this further or what adjustments to make.
Research and attempts:
I’ve confirmed that the video files are successfully uploaded to Firebase Storage.
The issue appears to be related to either the FFmpeg processing or the retrieval of the download URL for larger files.
I’ve searched for similar issues but haven’t found a solution specific to handling larger video files with FFmpeg and Firebase.
Request for help:
Any insights on why this error might be occurring for larger files? Suggestions for debugging or modifying the code to handle larger videos efficiently.