SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
357 stars 114 forks source link

ffmpeg not working #128

Closed yashkhandelwal05 closed 1 year ago

yashkhandelwal05 commented 1 year ago

I have tried out both ffmpeg.kill() and ffmpeg.stdin.destroy() But still it's not working.

SamuelScheit commented 1 year ago

I found a fix, you need to manually close the stdin stream, after the tab stream was closed:

stream.on("close", () => {
    ffmpeg.stdin.end();
});
yashkhandelwal05 commented 1 year ago

What is the use of the close callback for stream ? Will the await stream.destroy() line take time to close off the stream?

SamuelScheit commented 1 year ago

yes, it does. The stream has a delay of ~a second and it waits for the stream to end and send the last packet, until it closes the stream

yashkhandelwal05 commented 1 year ago

For longer duration videos>= 30 mins it's not working. The stream close is working but ffmpeg.stdin.end() is not working and I am not getting a close callback. await new Promise((resolve) => { ffmpeg.stdin.end(); ffmpeg.on('close', (code) => { console.log(FFmpeg process exited with code ${code}); resolve(); }); });

 I am using spawn instead of exec. Can that affect as well?
yashkhandelwal05 commented 1 year ago

I have tried using both exec and spawn but still its not working with videos of around 1 hr duration

SamuelScheit commented 1 year ago

I've let it run for an hour and it closes without problems:

image
yashkhandelwal05 commented 1 year ago

If I am not using : ffmpeg.stderr.on("data", (chunk) => { console.log(chunk.toString()); }); Then the ffmpeg is not ending but when I am using this it's getting ended. I guess this part of code should be optional as I don't want to have a continuous logging.

yashkhandelwal05 commented 1 year ago

Can you please try removing this part: ffmpeg.stderr.on("data", (chunk) => { console.log(chunk.toString()); }); And check whether it's working or not

yashkhandelwal05 commented 1 year ago

There is also problem with this line: const ffmpeg = exec(ffmpeg -y -i - -c copy output.mp4); I am getting this error. Can you please check?

WhatsApp Image 2023-08-08 at 1 17 54 PM

yashkhandelwal05 commented 1 year ago

@SamuelScheit any update?

SamuelScheit commented 1 year ago

works for me, can't replicate