ffmpegwasm / ffmpeg.wasm

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

single threaded version:can not use “ffmpeg.run” secondly. Throw Error "Program terminated with exit(0)" #436

Open TheSecondAkari opened 2 years ago

TheSecondAkari commented 2 years ago

I used the single threaded version。 It will work。 However, if I execute the run command twice, it will report an error [Program terminated with exit(0)], and once is normal

Screenshots image

image

EABangalore commented 2 years ago

@TheSecondAkari have you tried after running

await ffmpeg.run(....)
 var buffer = ffmpeg.FS('readFile','filename');
// Code to clear buffer

//Execute 2nd command
TheSecondAkari commented 2 years ago

@EABangalore image It error,too

TheSecondAkari commented 2 years ago

@EABangalore
image

TheSecondAkari commented 1 year ago

@yeliulee @Willy-JL Do you have time to help me? Thanks

yeliulee commented 1 year ago

@yeliulee @Willy-JL Do you have time to help me? Thanks

i just set EXIT_RUNTIME=0 before compiling the library.

raosan commented 1 year ago

i fixed it by removing the process.exit(0);

sovrgn commented 1 year ago

A good approach for now would be to implement a promise queue. Something along the lines:

let lastEnqued = Promise.resolve();

let queWrapper = async (fn) => {
    lastEnqued = lastEnqued.then(async()=>{
      let result = await ffmpeg.load().then((res) => {        
        return fn(res)
      })
      if(ffmpeg.isLoaded()) {
        ffmpeg.exit();
      }
      return result
    })
    return await lastEnqued;
}

Then wrap each ffmpeg operation in this wrapper function

return await queWrapper(async () => {
  ffmpeg.FS(........)
  await ffmpeg.run(.........)
})

Sadly without calling .load() before and .exit() after each time a command is run, I couldn't get it to behave nicely.

But generally this should get you at least to operational level.

EDIT: Keep in mind that if multiple ffmpeg.run(...) are required (e.g. for loop) there has to be an internal promise queue as well.