Skip to content

Commit

Permalink
Retry still image without skipping frames on failure
Browse files Browse the repository at this point in the history
Some videos can't be seeked, either because they are too short or
because the format doesn't support it. In this case, just take the very
first frame as still image.

Fixes thumbsup/thumbsup#76
  • Loading branch information
tribut authored and rprieto committed Jun 19, 2018
1 parent 1a79451 commit 53ab441
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const async = require('async')
const fs = require('fs')
const gm = require('gm')
const mkdirp = require('mkdirp')
const path = require('path')
Expand Down Expand Up @@ -100,6 +101,12 @@ exports.still = function (source, target, options, callback) {
}

function extractFrame (source, target, callback) {
const args = ['-ss', '0.1', '-i', source, '-vframes', 1, '-y', target]
ffmpeg.exec(args, callback)
const args = ['-i', source, '-vframes', 1, '-y', target]
ffmpeg.exec(['-ss', '0.1'].concat(args), (err) => {
if (fs.existsSync(target)) {
callback(err)
} else {
ffmpeg.exec(args, callback)
}
})
}
Binary file added test-data/expected/videos/single-frame.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test-data/input/videos/single-frame.mov
Binary file not shown.
8 changes: 8 additions & 0 deletions test/still.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ tape('extracts a frame from a very short video', (test) => {
})
})

tape('extracts a frame from a video that only has a single frame', (test) => {
diff.still(test, {
input: 'videos/single-frame.mov',
expect: 'videos/single-frame.jpg',
options: { height: 150 }
})
})

tape('extracts and crops a frame from an MP4 video', (test) => {
diff.still(test, {
input: 'videos/countdown.mp4',
Expand Down

0 comments on commit 53ab441

Please sign in to comment.