ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

Can't reuse ffmpeg

Open chicken-suop opened this issue 3 years ago • 7 comments

Describe the bug GIVEN I load ffmpeg AND I run any command AND I run another command THEN an error is thrown

[info] run ffmpeg command: -L
Uncaught (in promise) 
{
    "name": "ExitStatus",
    "message": "Program terminated with exit(0)",
    "status": 0
}

To Reproduce

const fs = require('fs');
const { createFFmpeg, fetchFile } = require('@ffmpeg/ffmpeg');

const ffmpeg = createFFmpeg({ log: true });

(async () => {
  await ffmpeg.load();
  await ffmpeg.run('-L');
  await ffmpeg.run('-L');
})();

Expected behavior It should run both commands

chicken-suop avatar Feb 25 '22 05:02 chicken-suop

If I call ffmpeg.run('-L') again I get a different error:

[info] run ffmpeg command: -L
Uncaught Error: ffmpeg.wasm can only run one command at a time
    at Object.run (a2f28db1-0ad0-4fe5-b551-976460876318:923:13)
    at <anonymous>:1:20

chicken-suop avatar Feb 25 '22 05:02 chicken-suop

I'm experiencing similar issues.

0x-ten avatar Mar 24 '22 18:03 0x-ten

Same issue for me whatever the command

6l3m avatar Mar 28 '22 14:03 6l3m

Hola en un tutorial de Digital Ocean menciona que "Dado que ffmpeg.wasm solo puede ejecutar una sola operación a la vez, necesitará una forma de serializar las solicitudes que ingresan y procesarlas una a la vez", en el tutorial utilizan p-queue para solucionar esto dejo en link a mi me funcionó. https://www.digitalocean.com/community/tutorials/how-to-build-a-media-processing-api-in-node-js-with-express-and-ffmpeg-wasm

JoelPucoDev avatar Jun 23 '22 16:06 JoelPucoDev

Very frustrating and almost inexplicable error which requires recreating the ffmpeg instance through createFFmpeg every time I want to run another frame extraction. Likely is related to the single threaded core setup.

Is this the way the library is supposed to work? That when you call run the object is now to be discarded after use?

Also when I call exit I get a similar error

Object { name: "ExitStatus", message: "Program terminated with exit(1)", status: 1 }
message: "Program terminated with exit(1)"
name: "ExitStatus"
status: 1
<prototype>: Object { … }

So in effect after using run, everything except fs can no longer be used.

I guess for some additional information if wanted: I'm running the single threaded browser version with proxy_main replaced with main

-- Edit: my issues to resolve this or get to a situation where I can work around it are futile. In addition to experiencing browser tab crashes on occasion, likely exit is not actually doing anything. I fear that in order to reach an explanation I will have to get into the core and start debugging it and this isn't currently in my plans. My workaround will likely be to direct the user to another tab/window where I can use the multithreaded capabilities and then attempt to get the information into the active tab through some means.

ECHibiki avatar Jun 23 '22 23:06 ECHibiki

I've been experiencing this same issue for the single-thread version.

The workaround that's working for my specific case is to recreate ffmpeg instance and run load function again after each use.

It's not probably the most optimal solution, but it's the best workaround I've found so far.

marcosdellavecchia avatar Aug 29 '22 15:08 marcosdellavecchia

I use both the single-threaded and the multi-threaded version in my app, and dynamically switch between the two when available, and I noticed that, when using the multithreaded one (proxy_main), I can successfully run two commands await ffmpeg.run.

However, when using the single-threaded version, the first command succeeds, but the second one just hangs forever. The last message from FFMPEG's logging is

...
[ffout] FFMPEG_END
[info] run ffmpeg command: -framerate ...

and then eternal hanging.

My solution was to: read the files from the first command into memory using ffmpeg.FS("readFile", then, await ffmpeg.exit(), then await ffmpeg.load(), then copy back the file from the previous run, plus all my other required files, and then run my second command.

This did the trick in single-threaded mode, but it's a shame I can't resuse the files I wrote the first time around.

Tested on ffmpeg-core version 11.4, compiled on commit 1f3461d.

usr-ein avatar Sep 06 '22 08:09 usr-ein