Skip to content

Commit

Permalink
feat: Argument override
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjscott committed Aug 21, 2019
2 parents 1d4fe57 + 0d70cc9 commit b4f4dc9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ Type: `String`

Seeks the video to the provided time. The time must be in the following form: `hh:mm:ss[.ms]`, eg. `00:00:42.23`. If omitted, the video time will be set to `00:00:00` (ie. the first frame).

#### config.args

Type: `Array<String>`

FFmpeg arguments that override the synthetic arguments created by `simple-thumbnail`; you'll likely need to pass include your own `-i` flag, `-y` flag, etc.

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
Expand Down
24 changes: 15 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,21 @@ function genThumbnail (input, output, size, config = {}) {
const rstream = typeof input === 'string' ? null : input
const wstream = typeof output === 'string' ? null : output

const parsedSize = parseSize(size)
const args = buildArgs(
typeof input === 'string' ? `"${input}"` : 'pipe:0',
typeof output === 'string' ? `"${output}"` : '-f singlejpeg pipe:1',
parsedSize,
seek
)

if (input === null && output === null) {
let args = ''
if (config.args) {
args = config.args
} else {
const parsedSize = parseSize(size)

args = buildArgs(
typeof input === 'string' ? `"${input}"` : 'pipe:0',
typeof output === 'string' ? `"${output}"` : '-f singlejpeg pipe:1',
parsedSize,
seek
)
}

if ((input === null && output === null) || config.args) {
return ffmpegDuplexExecute(ffmpegPath, args)
}
if (output === null) {
Expand Down
1 change: 1 addition & 0 deletions test/data/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is text
Binary file added test/expected/args-text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ async function httpMediaTestMacro (t, { url, title }) {
t.true(isSame)
}

async function withArgsMacro (t, { config, output }) {
await genThumbnail(null, null, null, config)

const textImageIsSame = await looksSame(absPath('./expected/args-text.png'), output, { tolerance: 5 })

t.true(textImageIsSame)
}

function streamReturnMacro (t, { input, title }) {
const output = absPath(`./out/${title}.png`)
const write = fs.createWriteStream(output)
Expand Down Expand Up @@ -115,6 +123,27 @@ test('creates thumbnails for streams', imageTestMacro, {
title: 'stream'
})

;(function () {
const title = 'args'
const text = absPath('./data/text.txt')
const output = absPath(`./out/${title}.png`)
const fontPath = absPath('./utils/opensans.ttf')

test('can pass args to ffmpeg via config', withArgsMacro, {
config: {
args: [
'-f lavfi',
'-i color=c=white:s=640x480:d=5.396',
`-filter_complex "drawtext=textfile='${text}':x=0:y=0:fontsize=30:fontcolor=ff00ff:fontfile=${fontPath}"`,
'-y',
output
],
path: ffmpeg.path
},
output
})
})()

test('creates thumbnails for http', httpMediaTestMacro, {
url: 'http://www.w3schools.com/html/mov_bbb.webm',
title: 'http'
Expand Down
Binary file added test/utils/opensans.ttf
Binary file not shown.

0 comments on commit b4f4dc9

Please sign in to comment.