Browse Source

improve error handling #24

pull/44/head
Mikael Finstad 6 years ago
parent
commit
c692dbd26e
  1. 12
      index.js
  2. 2
      sources/videoFrameSource.js

12
index.js

@ -280,7 +280,7 @@ module.exports = async (config = {}) => {
]; ];
const args = [ const args = [
...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'panic']),
...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']),
'-f', 'rawvideo', '-f', 'rawvideo',
'-vcodec', 'rawvideo', '-vcodec', 'rawvideo',
@ -308,6 +308,13 @@ module.exports = async (config = {}) => {
try { try {
outProcess = startFfmpegWriterProcess(); outProcess = startFfmpegWriterProcess();
let outProcessError;
// If we don't catch it here, the whole process will crash and we cannot process the error
outProcess.stdin.on('error', (err) => {
console.error('Output ffmpeg caught error', err);
outProcessError = err;
});
let totalFrameCount = 0; let totalFrameCount = 0;
let fromClipFrameCount = 0; let fromClipFrameCount = 0;
@ -394,7 +401,8 @@ module.exports = async (config = {}) => {
// If we don't await we get EINVAL when dealing with high resolution files (big writes) // If we don't await we get EINVAL when dealing with high resolution files (big writes)
await new Promise((r) => outProcess.stdin.write(outFrameData, () => r())); await new Promise((r) => outProcess.stdin.write(outFrameData, () => r()));
// outProcess.stdin.write(outFrameData);
if (outProcessError) throw outProcessError;
fromClipFrameCount += 1; fromClipFrameCount += 1;
} }

2
sources/videoFrameSource.js

@ -29,7 +29,7 @@ module.exports = async ({ width, height, channels, framerateStr, verbose, enable
// Testing: ffmpeg -i 'vid.mov' -t 1 -vcodec rawvideo -pix_fmt rgba -f image2pipe - | ffmpeg -f rawvideo -vcodec rawvideo -pix_fmt rgba -s 2166x1650 -i - -vf format=yuv420p -vcodec libx264 -y out.mp4 // Testing: ffmpeg -i 'vid.mov' -t 1 -vcodec rawvideo -pix_fmt rgba -f image2pipe - | ffmpeg -f rawvideo -vcodec rawvideo -pix_fmt rgba -s 2166x1650 -i - -vf format=yuv420p -vcodec libx264 -y out.mp4
// https://trac.ffmpeg.org/wiki/ChangingFrameRate // https://trac.ffmpeg.org/wiki/ChangingFrameRate
const args = [ const args = [
...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'panic']),
...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']),
...(cutFrom ? ['-ss', cutFrom] : []), ...(cutFrom ? ['-ss', cutFrom] : []),
'-i', path, '-i', path,
...(cutTo ? ['-t', (cutTo - cutFrom) * framePtsFactor] : []), ...(cutTo ? ['-t', (cutTo - cutFrom) * framePtsFactor] : []),

Loading…
Cancel
Save