Skip to content

Commit

Permalink
fix: Switch to duplexify (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjscott committed May 12, 2019
1 parent bbe0076 commit b3b1a09
Show file tree
Hide file tree
Showing 6 changed files with 331 additions and 2,200 deletions.
27 changes: 2 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { spawn } = require('child_process')
const { Duplex } = require('stream')
const duplexify = require('duplexify')

/**
* Parse a size string (eg. '240x?')
Expand Down Expand Up @@ -125,28 +125,6 @@ function ffmpegStreamExecute (path, args, rstream) {
return Promise.resolve(ffmpeg.stdout)
}

class DuplexFfmpeg extends Duplex {
constructor (ffmpeg) {
super()
this.ffmpeg = ffmpeg
}

_read (size) {
this.ffmpeg.stdout.on('data', data => {
this.push(data)
})
}

_write (...args) {
this.ffmpeg.on('close', () => {
this.end()
})
this.ffmpeg.stdin._write(...args)
}

_final () {}
}

/**
* Return a duplex stream
* @func ffmpegDuplexExecute
Expand All @@ -158,7 +136,7 @@ class DuplexFfmpeg extends Duplex {
function ffmpegDuplexExecute (path, args) {
const ffmpeg = spawn(path, args, { shell: true })

return new DuplexFfmpeg(ffmpeg)
return duplexify(ffmpeg.stdin, ffmpeg.stdout)
}

/**
Expand Down Expand Up @@ -187,7 +165,6 @@ function genThumbnail (input, output, size, config = {}) {
)

if (input === null && output === null) {
console.log(args)
return ffmpegDuplexExecute(ffmpegPath, args)
}
if (output === null) {
Expand Down

0 comments on commit b3b1a09

Please sign in to comment.