ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
14.22k stars 831 forks source link

on("progress") -> ProgressEvent -> returning unknown random values for progress #550

Closed DeanVanGreunen closed 1 year ago

DeanVanGreunen commented 1 year ago

Describe the bug progress value from the ProgressEvent is a large negative number like -12202300 (for example)

To Reproduce

ffmpeg.on("progress", ({ progress, time }) => {
    // Progress is supposed to be in the range of 0 to 1 as a floating point number.
    setPercentage(Math.round(progress * 100));
 });

Expected behavior progress value from the ProgressEvent is supposed to be in the range of 0 to 1 as a floating point number.

Desktop (please complete the following information):

jeromewu commented 1 year ago

Please use time instead as progress is highly experimental and lots of edge cases are not covered.

DeanVanGreunen commented 1 year ago

@jeromewu what does the time value represent? time remaining, time passed, ???

jeromewu commented 1 year ago

time passed

https://github.com/ffmpegwasm/ffmpeg.wasm/blob/main/packages/types/types/index.d.ts#L78

DeanVanGreunen commented 1 year ago

@jeromewu how would I get the duration of the video? here is a snippet of my code

import { FFmpeg } from '@ffmpeg/ffmpeg';
import { fetchFile } from '@ffmpeg/util';

const baseURL = 'https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd'
        const ffmpeg = ffmpegRef.current;
        ffmpeg.on("progress", ({ progress, time }) => {
            console.log("PROGRESS DATA", progress, time);
            // TODO: CALCULATE THE PERCENTAGE SOMEHOW
            //setPercentage(Math.round(progress * 100));
        });
        ffmpeg.on("log", ({ message }) => {
            console.log("LOG DATA", message);
        });
        await ffmpeg.load({
            coreURL: await toBlobURL(
                `${baseURL}/ffmpeg-core.js`,
                "text/javascript",
            ),
            wasmURL: await toBlobURL(
                `${baseURL}/ffmpeg-core.wasm`,
                "application/wasm",
            ),
        });

let fileWritten = await ffmpeg.writeFile(
                    `${questionData.id}.webm`, await fetchFile(blob)
                );

let converted = await ffmpeg.exec([
                        '-i', `${questionData.id}.webm`, // Input File
                        '-c:v', 'libx264',
                        '-preset', 'ultrafast',
                        '-vprofile', 'high',
                        '-pix_fmt', 'yuv420p',
                        '-r', '15', // Frame Rate
                        '-c:a', 'copy',
                        '-crf', '32',
                        '-vf', 'scale=320:-1', // Filter -> Scale image to 320px width, maintaining aspect ratio
                        `${questionData.id}-compressed.mp4` // Output File
                    ]);
jeromewu commented 1 year ago

https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds

You can get output using on('log', ...)

deifos commented 3 days ago

@DeanVanGreunen did you get this working?

DeanVanGreunen commented 2 days ago

@DeanVanGreunen did you get this working?

Sadly not, haven't tested the newer versions yet, so it might have been fixed, I suggest you pull/include the new version and give it a test