Skip to content

Commit

Permalink
Merge 596d7d1 into b03837f
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed Jul 19, 2019
2 parents b03837f + 596d7d1 commit 0593b99
Show file tree
Hide file tree
Showing 4 changed files with 1,572 additions and 1,322 deletions.
8 changes: 4 additions & 4 deletions lib/compile-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = compileVideo
* @param {Number} initialFrame Frame number the sequence starts on
* @return {Promise<String>} Returns the path to the saved video file
*/
function compileVideo (
async function compileVideo (
frameDir,
{
outDir = process.cwd(),
Expand All @@ -29,11 +29,11 @@ function compileVideo (
validate('S|SO', arguments)
validate('SSNS', [outDir, filename, fps, frameFormat])

return new Promise(async (resolve, reject) => {
const framesPath = join(frameDir, `%d.${frameFormat}`)
const framesPath = join(frameDir, `%d.${frameFormat}`)

await mkdir(outDir)
await mkdir(outDir)

return new Promise((resolve, reject) => {
// spawn a child process and use ffmpeg to compile frames to video file
const ffmpeg = spawn(ffmpegPath, [
'-v', 'warning',
Expand Down
40 changes: 17 additions & 23 deletions lib/frame-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ async function FrameMaker (
let imageData
for (let sample = 0; sample < samplesPerFrame; sample++) {
const sampleFrame = frame + sample * shutterAngle / samplesPerFrame
try {
await drawFrame(sampleFrame, canvas, context)
} catch (error) { throw error }
await drawFrame(sampleFrame, canvas, context)
imageData = context.getImageData(0, 0, width, height)
for (let idx = 0; idx < imageData.data.length; idx++) {
composite[idx] += imageData.data[idx]
Expand All @@ -145,27 +143,23 @@ async function FrameMaker (
* @param {Number} frame The current frame number
* @return {Promise<Buffer>} Resolves to an image buffer
*/
getFrame (frame) {
return new Promise(async (resolve, reject) => {
let canvas, context
if (renderInParallel) {
canvas = createCanvas(width, height)
context = canvas.getContext('2d')
} else {
canvas = rootCanvas
context = rootContext
}

try {
if (samplesPerFrame > 1) {
await drawWithMotionBlur(frame, canvas, context)
} else {
await drawFrame(frame, canvas, context)
}
} catch (error) {
reject(error)
}
async getFrame (frame) {
let canvas, context
if (renderInParallel) {
canvas = createCanvas(width, height)
context = canvas.getContext('2d')
} else {
canvas = rootCanvas
context = rootContext
}

if (samplesPerFrame > 1) {
await drawWithMotionBlur(frame, canvas, context)
} else {
await drawFrame(frame, canvas, context)
}

return new Promise((resolve, reject) => {
canvas.toBuffer(
function (error, buffer) {
if (error) reject(error)
Expand Down
Loading

0 comments on commit 0593b99

Please sign in to comment.