philipjscott / simple-thumbnail

A library that produces thumbnails from images, videos and URLs :mag_right:
https://www.npmjs.com/package/simple-thumbnail
MIT License
25 stars 14 forks source link

response readable-stream 0 length #68

Closed mu-hasan closed 3 years ago

mu-hasan commented 4 years ago

I'm using meteor.js, in development it's running well. But after I compiled, the response readable-stream is 0 length.

To Reproduce

const SimpleThumbnail = require('simple-thumbnail')
const StreamBuffers = require('stream-buffers')
const ffmpeg = require('ffmpeg-static');
s3Bucket.getObject(s3params, function (err, data) {
    if (err) {
        console.log('vt-s3-getObject', err);
        return myFuture.return({code: err.statusCode, headers: {}, body: null});
    }

    let source = new StreamBuffers.ReadableStreamBuffer();
    source.put(data.Body);
    console.log('s3Data', data); //called

    SimpleThumbnail(source, null, `${width}x${height}`, {path: ffmpeg.path}).then(function (res) {
        console.log('simple-thumbnail-res', res); //called
        let chunks = [];
        res.on('data', function (chunk) {
            console.log('simple-thumbnail-chunk', chunk); //not-called
            chunks.push(chunk);
        });
        res.on('end', function () {
            console.log('simple-thumbnail-end'); //called
            let imgContent = Buffer.concat(chunks);
            console.log('imgContent', imgContent.length); //called
        })
    }).catch(function (err) {
        console.log('simple-thumbnail-err', err);
    });
});

LOG RESULT s3Data

{
  AcceptRanges: 'bytes',
  LastModified: 2020-04-06T03:46:20.000Z,
  ContentLength: 18041,
  ETag: '"88b41e76bca00b274b4bd9f63a3eb41f"',
  ContentType: 'video/mp4',
  Metadata: {},
  Body: <Buffer 00 00 00 20 66 74 79 70 69 73 6f 6d 00 00 02 00 69 73 6f 6d 69 73 6f 32 61 76 63 31 6d 70 34 31 00 00 00 08 66 72 65 65 00 00 40 db 6d 64 61 74 00 00 ... 17991 more bytes>
}

simple-thumbnail-res

Socket {
  connecting: false,
  _hadError: false,
  _parent: null,
  _host: null,
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: null,
    pipesCount: 0,
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: true,
    sync: false,
    needReadable: true,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    emitClose: false,
    autoDestroy: false,
    destroyed: false,
    defaultEncoding: 'utf8',
    awaitDrain: 0,
    readingMore: false,
    decoder: null,
    encoding: null,
    [Symbol(kPaused)]: null
  },
  readable: true,
  _events: [Object: null prototype] {
    end: [Function: onReadableStreamEnd],
    close: [Function]
  },
  _eventsCount: 2,
  _maxListeners: undefined,
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,
    needDrain: false,
    ending: false,
    ended: false,
    finished: false,
    destroyed: false,
    decodeStrings: false,
    defaultEncoding: 'utf8',
    length: 0,
    writing: false,
    corked: 0,
    sync: true,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: null,
    writelen: 0,
    afterWriteTickInfo: null,
    bufferedRequest: null,
    lastBufferedRequest: null,
    pendingcb: 0,
    prefinished: false,
    errorEmitted: false,
    emitClose: false,
    autoDestroy: false,
    bufferedRequestCount: 0,
    corkedRequestsFree: {
      next: null,
      entry: null,
      finish: [Function: bound onCorkedFinish]
    }
  },
  writable: false,
  allowHalfOpen: false,
  _sockname: null,
  _pendingData: null,
  _pendingEncoding: '',
  server: null,
  _server: null,
  [Symbol(asyncId)]: 32731,
  [Symbol(kHandle)]: Pipe { reading: true, [Symbol(owner)]: [Circular] },
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kCapture)]: false,
  [Symbol(kBytesRead)]: 0,
  [Symbol(kBytesWritten)]: 0
}

imgContent: 0

Environment (please complete the following information):

kxait commented 4 years ago

i'm getting this too; i'm also getting a mysterious Write EOF error when making WEBM thumbnails, i'm pretty sure it's related

philipjscott commented 4 years ago

@kxait

Can you please upload the .webm that's causing issues? I'll try and debug it whenever I'm free.

Sorry for this repo being a bit neglected; I'm currently working on a startup and it's eating a lot of my time @_@

kxait commented 4 years ago

@ScottyFillups Hi, it turned out it was an error with my implementation and I was wrong. The package works perfectly. It's good to note that Read and Write Streams are a bit fiddly with GridFS Streams. The resolution was to pipe the GridFS connection to a file and do everything on disk. Thanks for the reply!

philipjscott commented 4 years ago

@mu-hasan

Sorry for the late reply. I checked your code; I don't think you need to use stream-buffer. I think you should be able to just pass in data.Body directly into simple-thumbnail.

philipjscott commented 3 years ago

Closing because there doesn't seem to be an issue here.

@mu-hasan let me know if you're still having issues :+1: