SamuelScheit / puppeteer-stream

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

[Bug] missing metadata #14

Closed KennyHarrer closed 2 years ago

KennyHarrer commented 2 years ago

my code

After messing around for awhile I learned that you have to use --start-fullscreen to get a full capture of the page you want to record. Video outputs, plays, however it seems to missing the "end time". Any idea how I would go about fixing this?

Screenshot of playback bar in vlc

SamuelScheit commented 2 years ago

Oh this might be because the stream is immediately stopped and no end metadata is written. I’ll try what I can do about it

KennyHarrer commented 2 years ago

https://github.com/yusitnikov/fix-webm-duration

amjd commented 2 years ago

This package works great on the overall, so thanks for that @Flam3rboy! While playing the generated videos, I came across the same issue. It's not possible to seek the video because of the missing metadata.

Integrating @KennyHarrer's linked solution might resolve this. I tried using it to post-process the video using Nodejs, but looks like the script is not designed to work on the server-side.

On a related note, how is it that MediaRecorder API doesn't add metadata on its own? That seems like a huge drawback. Or is there a way to add it that we aren't aware of?

KennyHarrer commented 2 years ago

Video output also seems to be corrupted. After fixing the video length with ffmpeg -err_detect ignore_err -i test.webm -c copy test_fixed.webm Video is missing audio, artifacts near the end, and is missing all motion. Video has same errors before fixing the video length.

KennyHarrer commented 2 years ago

https://youtu.be/v6iCQW-1t4k

KennyHarrer commented 2 years ago

Oddly enough the video plays fine on youtube... Not sure how that works. The video is still missing audio though.

InsideBSITheSecond commented 2 years ago

I fixed this by piping it to a ffmpeg instead of an fs stream You do that by doing (this is assuming an audio stream) (and you need to have ffmpeg binaries installed)

const { exec } = require("child_process");
ffmpeg = exec(`ffmpeg -y -i - output.wav`);
stream.pipe(ffmpeg.stdin);
[[...stuff...]]
stream.unpipe(ffmpeg);
ffmpeg.kill();

might be unnecessary to unpipe but since it's in my code and it works... ¯\(ツ)

SamuelScheit commented 2 years ago

This is an known bug of Media Encoder, but you could use @InsideBSITheSecond workaround

rubens21 commented 1 year ago

hey @SamuelScheit ,

First off, thanks for this package! It has been incredible useful.

I wonder how much certain are you about Media Encoder being to blame for this problem.

The @InsideBSITheSecond workaround to fix the problem, but then the video isn't complete. A considerable part of the video is trimmed. In a 30s recording, the final file brings only 10 or 15s.

The problem may be on the Readable stream. The last data chunk maybe have been lost when the stream is destroyed. I came to this suspicion because the events finish or end are never called for stream nor for the pipe destination (file or child_process).

Ideally, the stream should be ended instead of destroyed.

I am not expert in streaming, so I would not be surprised I am wrong :-)

I tried to work on this problem in your source code, but unfortunately I ran out of time before making it work. :-/

I hope this comments will help someone to fix it soner or later.