Completed the getVideoInfo func according to the comment specified
This commit is contained in:
@ -108,20 +108,46 @@ export const getVideoInfo = async (videoFile: File): Promise<{
|
|||||||
// Write input file
|
// Write input file
|
||||||
await ffmpeg.writeFile(inputName, new Uint8Array(await videoFile.arrayBuffer()));
|
await ffmpeg.writeFile(inputName, new Uint8Array(await videoFile.arrayBuffer()));
|
||||||
|
|
||||||
// Get video info
|
// Capture FFmpeg stderr output
|
||||||
|
let ffmpegOutput = '';
|
||||||
|
const listener = (data: string) => {
|
||||||
|
ffmpegOutput += data;
|
||||||
|
};
|
||||||
|
ffmpeg.on('log', ({ message }) => listener(message));
|
||||||
|
|
||||||
|
// Run ffmpeg to get info (stderr will contain the info)
|
||||||
await ffmpeg.exec(['-i', inputName, '-f', 'null', '-']);
|
await ffmpeg.exec(['-i', inputName, '-f', 'null', '-']);
|
||||||
|
|
||||||
// Note: In a real implementation, you'd parse the FFmpeg output
|
// Remove listener
|
||||||
// For now, we'll return default values and enhance this later
|
// (No off() method in ffmpeg.wasm, so this is a no-op, but included for clarity)
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
await ffmpeg.deleteFile(inputName);
|
await ffmpeg.deleteFile(inputName);
|
||||||
|
|
||||||
|
// Parse output for duration, resolution, and fps
|
||||||
|
// Example: Duration: 00:00:10.00, start: 0.000000, bitrate: 1234 kb/s
|
||||||
|
// Example: Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
|
||||||
|
|
||||||
|
const durationMatch = ffmpegOutput.match(/Duration: (\d+):(\d+):([\d.]+)/);
|
||||||
|
let duration = 0;
|
||||||
|
if (durationMatch) {
|
||||||
|
const [, h, m, s] = durationMatch;
|
||||||
|
duration = parseInt(h) * 3600 + parseInt(m) * 60 + parseFloat(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
const videoStreamMatch = ffmpegOutput.match(/Video:.* (\d+)x(\d+)[^,]*, ([\d.]+) fps/);
|
||||||
|
let width = 0, height = 0, fps = 0;
|
||||||
|
if (videoStreamMatch) {
|
||||||
|
width = parseInt(videoStreamMatch[1]);
|
||||||
|
height = parseInt(videoStreamMatch[2]);
|
||||||
|
fps = parseFloat(videoStreamMatch[3]);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
duration: 10, // Placeholder - would parse from FFmpeg output
|
duration,
|
||||||
width: 1920, // Placeholder
|
width,
|
||||||
height: 1080, // Placeholder
|
height,
|
||||||
fps: 30 // Placeholder
|
fps
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user