Closed uwemaurer closed 1 year ago
fixes #167
Thanks for your PR. What is the exact reason why ffmpeg is returning too big frames? Is it because we're using the wrong stream to calculate frameByteSize
? If so, then maybe the better solution would be to use the correct stream to calculate this value
Sorry my PR description was unclear.
ffmpeg returns the frames exactly the right way, also the frameByteSize
calculation is correct.
The problem in the existing code is how it handles the data from the input stream. The data comes in chunks and the code assumes that there is at most one frame in each chunk. However if the video is resized to a small resolution, the chunk size can be larger than the size of a frame (in my case there were 4 frames in one chunk since the chunk size was 64kb and the frame size 16kb).
This chunk size doesn't come from ffmpeg but from node or the operating system. It can probably also vary between different versions. The code should be able to handle any chunk size correctly wheter it is smaller or larger than a frame.
So this pull request fixes this.
any update?
thanks!
Fix bug in videoFrameSource.js when the video frame buffer is too small to store the buffer received from ffmpeg.
I was trying to embed small video thumbnails in a video and got an exception in
videoFrameSource.js
.The problem was that the buffer can be very small then, eg 64x64 x 4 bytes (=16384 frame buffer length), but ffmpeg returns up to 64kb chunks.
This change fixes the case where ffmpeg returns such chunks which contain multiple frames.