Browse Source

fix broken renderSingleFrame logic

layer-manipulation
Mikael Finstad 6 years ago
parent
commit
bded8b9e5a
  1. 2
      examples/renderSingleFrame.js
  2. 8
      index.js

2
examples/renderSingleFrame.js

@ -8,4 +8,4 @@ const { renderSingleFrame } = require('..');
time: 0, time: 0,
clips: JSON5.parse(await fs.readFile('./videos.json5', 'utf-8')).clips, clips: JSON5.parse(await fs.readFile('./videos.json5', 'utf-8')).clips,
}); });
})().catch(console.error);
})().catch(console.error);

8
index.js

@ -385,16 +385,16 @@ async function renderSingleFrame({
outPath = `${Math.floor(Math.random() * 1e12)}.png`, outPath = `${Math.floor(Math.random() * 1e12)}.png`,
}) { }) {
const clips = await parseConfig({ defaults, clips: clipsIn, allowRemoteRequests, ffprobePath }); const clips = await parseConfig({ defaults, clips: clipsIn, allowRemoteRequests, ffprobePath });
let totalDuration = 0;
let clipStartTime = 0;
const clip = clips.find((c) => { const clip = clips.find((c) => {
if (totalDuration >= time) return true;
totalDuration += c.duration;
if (clipStartTime <= time && clipStartTime + c.duration > time) return true;
clipStartTime += c.duration;
return false; return false;
}); });
assert(clip, 'No clip found at requested time'); assert(clip, 'No clip found at requested time');
const clipIndex = clips.indexOf(clip); const clipIndex = clips.indexOf(clip);
const frameSource = await createFrameSource({ clip, clipIndex, width, height, channels, verbose, logTimes, ffmpegPath, ffprobePath, enableFfmpegLog, framerateStr: '1' }); const frameSource = await createFrameSource({ clip, clipIndex, width, height, channels, verbose, logTimes, ffmpegPath, ffprobePath, enableFfmpegLog, framerateStr: '1' });
const rgba = await frameSource.readNextFrame({ time });
const rgba = await frameSource.readNextFrame({ time: time - clipStartTime });
// TODO converting rgba to png can be done more easily? // TODO converting rgba to png can be done more easily?
const canvas = createFabricCanvas({ width, height }); const canvas = createFabricCanvas({ width, height });

Loading…
Cancel
Save