AWS Lambda: ffmpeg thumbnails Генератор: пустой JPG - PullRequest
0 голосов
/ 09 февраля 2020

Когда видео загружено на S3, я хочу сохранить скриншот JPG.

В лямбда-функции с amazon AWS я делаю:

...

  let tmpFile = createWriteStream(`/tmp/screenshot.jpg`)

  var ffmpeg = spawn(ffmpegPath, [
      "-ss","00:00:05",
      "-i", target,
      "-vf", "thumbnail,scale=200:200", 
      "-qscale:v" ,"2",
      "-frames:v", "1",
      "-f", "image2",
      "-c:v", "mjpeg",
      "pipe:1"
    ]);

  ffmpeg.stdout.pipe(tmpFile).on("error", err => {
      console.log("Error A: ",err);
    });

  ffmpeg.on('error', err => {
    console.log("Error B", err)
    reject()
  })

  ffmpeg.on('close', code => {
    tmpFile.end();
    console.log('Log A', ffmpeg);

    child_process.exec("echo `ls -l -R /tmp`",
      (error, stdout, stderr) => {
        console.log(stdout)
    });

    resolve()
  })
...

Но результат пустой файл JPG в S3.

Журналы не показывают ошибок, моя «цель» в порядке, stdout ls показывает мне пустой файл JPG.

Я пробовал много вещей, например, использование другая версия ffmpeg, но такая же.

Существует "console.log ('Log A', ffmpeg)":

ChildProcess {
 _events: [Object: null prototype] { error: [Function], close: [Function] },
 _eventsCount: 2,
 _maxListeners: undefined,
 _closesNeeded: 3,
 _closesGot: 3,
 connected: false,
 signalCode: 'SIGSEGV',
 exitCode: null,
 killed: false,
 spawnfile: '/opt/nodejs/ffmpeg',
 _handle: null,
 spawnargs: [
   '/opt/nodejs/ffmpeg',
   '-ss',
   '00:00:05',
   '-i',
   'https://xxxxxxxxx',
   '-vf',
   'thumbnail,scale=200:200',
   '-qscale:v',
   '2',
   '-frames:v',
   '1',
   '-f',
   'image2',
   '-v',
   '16',
   '-c:v',
   'mjpeg',
   'pipe:1'
 ],
 pid: 24,
 stdin: 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: false,
     sync: true,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     paused: true,
     emitClose: false,
     autoDestroy: false,
     destroyed: true,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null
   },
   readable: false,
   _events: [Object: null prototype] { end: [Function: onReadableStreamEnd] },
   _eventsCount: 1,
   _maxListeners: undefined,
   _writableState: WritableState {
     objectMode: false,
     highWaterMark: 16384,
     finalCalled: false,
     needDrain: false,
     ending: false,
     ended: false,
     finished: false,
     destroyed: true,
     decodeStrings: false,
     defaultEncoding: 'utf8',
     length: 0,
     writing: false,
     corked: 0,
     sync: true,
     bufferProcessing: false,
     onwrite: [Function: bound onwrite],
     writecb: null,
     writelen: 0,
     bufferedRequest: null,
     lastBufferedRequest: null,
     pendingcb: 0,
     prefinished: false,
     errorEmitted: false,
     emitClose: false,
     autoDestroy: false,
     bufferedRequestCount: 0,
     corkedRequestsFree: [Object]
   },
   writable: false,
   allowHalfOpen: false,
   _sockname: null,
   _pendingData: null,
   _pendingEncoding: '',
   server: null,
   _server: null,
   [Symbol(asyncId)]: 5,
   [Symbol(kHandle)]: null,
   [Symbol(lastWriteQueueSize)]: 0,
   [Symbol(timeout)]: null,
   [Symbol(kBuffer)]: null,
   [Symbol(kBufferCb)]: null,
   [Symbol(kBufferGen)]: null,
   [Symbol(kBytesRead)]: 0,
   [Symbol(kBytesWritten)]: 0
 },
 stdout: 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: false,
     ended: true,
     endEmitted: true,
     reading: false,
     sync: false,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     paused: false,
     emitClose: false,
     autoDestroy: false,
     destroyed: true,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null
   },
   readable: false,
   _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: true,
     decodeStrings: false,
     defaultEncoding: 'utf8',
     length: 0,
     writing: false,
     corked: 0,
     sync: true,
     bufferProcessing: false,
     onwrite: [Function: bound onwrite],
     writecb: null,
     writelen: 0,
     bufferedRequest: null,
     lastBufferedRequest: null,
     pendingcb: 0,
     prefinished: false,
     errorEmitted: false,
     emitClose: false,
     autoDestroy: false,
     bufferedRequestCount: 0,
     corkedRequestsFree: [Object]
   },
   writable: false,
   allowHalfOpen: false,
   _sockname: null,
   _pendingData: null,
   _pendingEncoding: '',
   server: null,
   _server: null,
   write: [Function: writeAfterFIN],
   [Symbol(asyncId)]: 6,
   [Symbol(kHandle)]: null,
   [Symbol(lastWriteQueueSize)]: 0,
   [Symbol(timeout)]: null,
   [Symbol(kBuffer)]: null,
   [Symbol(kBufferCb)]: null,
   [Symbol(kBufferGen)]: null,
   [Symbol(kBytesRead)]: 0,
   [Symbol(kBytesWritten)]: 0
 },
 stderr: 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: true,
     endEmitted: true,
     reading: false,
     sync: false,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     paused: true,
     emitClose: false,
     autoDestroy: false,
     destroyed: true,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null
   },
   readable: false,
   _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: true,
     decodeStrings: false,
     defaultEncoding: 'utf8',
     length: 0,
     writing: false,
     corked: 0,
     sync: true,
     bufferProcessing: false,
     onwrite: [Function: bound onwrite],
     writecb: null,
     writelen: 0,
     bufferedRequest: null,
     lastBufferedRequest: null,
     pendingcb: 0,
     prefinished: false,
     errorEmitted: false,
     emitClose: false,
     autoDestroy: false,
     bufferedRequestCount: 0,
     corkedRequestsFree: [Object]
   },
   writable: false,
   allowHalfOpen: false,
   _sockname: null,
   _pendingData: null,
   _pendingEncoding: '',
   server: null,
   _server: null,
   write: [Function: writeAfterFIN],
   [Symbol(asyncId)]: 7,
   [Symbol(kHandle)]: null,
   [Symbol(lastWriteQueueSize)]: 0,
   [Symbol(timeout)]: null,
   [Symbol(kBuffer)]: null,
   [Symbol(kBufferCb)]: null,
   [Symbol(kBufferGen)]: null,
   [Symbol(kBytesRead)]: 0,
   [Symbol(kBytesWritten)]: 0
 },
 stdio: [
   Socket {
     connecting: false,
     _hadError: false,
     _parent: null,
     _host: null,
     _readableState: [ReadableState],
     readable: false,
     _events: [Object: null prototype],
     _eventsCount: 1,
     _maxListeners: undefined,
     _writableState: [WritableState],
     writable: false,
     allowHalfOpen: false,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: null,
     _server: null,
     [Symbol(asyncId)]: 5,
     [Symbol(kHandle)]: null,
     [Symbol(lastWriteQueueSize)]: 0,
     [Symbol(timeout)]: null,
     [Symbol(kBuffer)]: null,
     [Symbol(kBufferCb)]: null,
     [Symbol(kBufferGen)]: null,
     [Symbol(kBytesRead)]: 0,
     [Symbol(kBytesWritten)]: 0
   },
   Socket {
     connecting: false,
     _hadError: false,
     _parent: null,
     _host: null,
     _readableState: [ReadableState],
     readable: false,
     _events: [Object: null prototype],
     _eventsCount: 2,
     _maxListeners: undefined,
     _writableState: [WritableState],
     writable: false,
     allowHalfOpen: false,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: null,
     _server: null,
     write: [Function: writeAfterFIN],
     [Symbol(asyncId)]: 6,
     [Symbol(kHandle)]: null,
     [Symbol(lastWriteQueueSize)]: 0,
     [Symbol(timeout)]: null,
     [Symbol(kBuffer)]: null,
     [Symbol(kBufferCb)]: null,
     [Symbol(kBufferGen)]: null,
     [Symbol(kBytesRead)]: 0,
     [Symbol(kBytesWritten)]: 0
   },
   Socket {
     connecting: false,
     _hadError: false,
     _parent: null,
     _host: null,
     _readableState: [ReadableState],
     readable: false,
     _events: [Object: null prototype],
     _eventsCount: 2,
     _maxListeners: undefined,
     _writableState: [WritableState],
     writable: false,
     allowHalfOpen: false,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: null,
     _server: null,
     write: [Function: writeAfterFIN],
     [Symbol(asyncId)]: 7,
     [Symbol(kHandle)]: null,
     [Symbol(lastWriteQueueSize)]: 0,
     [Symbol(timeout)]: null,
     [Symbol(kBuffer)]: null,
     [Symbol(kBufferCb)]: null,
     [Symbol(kBufferGen)]: null,
     [Symbol(kBytesRead)]: 0,
     [Symbol(kBytesWritten)]: 0
   }
 ]
} ```
...