Creatomate / video-rendering-nodejs-ffmpeg

Video Rendering with Node.js and FFmpeg
MIT License
27 stars 16 forks source link

ffmpeg exited with code 1: av_interleaved_write_frame(): Input/output error #1

Closed umaar closed 1 year ago

umaar commented 1 year ago

Thanks for this! Getting some errors, any ideas?

 ➜ node src/index.js
Extracting frames from video 1...
file:///Users/umarhansa/Downloads/video-rendering-nodejs-ffmpeg-main/src/utils/extractFramesFromVideo.js:18
      .on('error', (error) => reject(new Error(error)));
                                     ^

Error: Error: ffmpeg exited with code 1: av_interleaved_write_frame(): Input/output error
frame=   19 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.05 bitrate=N/A dup=11 drop=0 speed=0.129x
video:3208kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

    at FfmpegCommand.<anonymous> (file:///Users/umarhansa/Downloads/video-rendering-nodejs-ffmpeg-main/src/utils/extractFramesFromVideo.js:18:38)
    at FfmpegCommand.emit (node:events:513:28)
    at emitEnd (/Users/umarhansa/Downloads/video-rendering-nodejs-ffmpeg-main/node_modules/fluent-ffmpeg/lib/processor.js:424:16)
    at endCB (/Users/umarhansa/Downloads/video-rendering-nodejs-ffmpeg-main/node_modules/fluent-ffmpeg/lib/processor.js:544:13)
    at handleExit (/Users/umarhansa/Downloads/video-rendering-nodejs-ffmpeg-main/node_modules/fluent-ffmpeg/lib/processor.js:170:11)
    at Socket.<anonymous> (/Users/umarhansa/Downloads/video-rendering-nodejs-ffmpeg-main/node_modules/fluent-ffmpeg/lib/processor.js:197:11)
    at Socket.emit (node:events:525:35)
    at Pipe.<anonymous> (node:net:298:12)

Node.js v19.1.0
nthonymiller commented 1 year ago

Getting exact same error, did you manage to work this out?

nthonymiller commented 1 year ago

Figured it out, I'm using windows and the output directory needs to exist for generating frames. I updated this function:

export async function extractFramesFromVideo(inputFilepath, outputFilepath, frameRate) {

  await new Promise((resolve, reject) => {

  // Ensure output path exists
    const filePath = dirname(outputFilepath);
    if (!existsSync(filePath)) {
      console.log('Path does not exist');
      mkdirSync(filePath);
    }

    ffmpeg()

      // Specify the filepath to the video
      .input(inputFilepath)

      // Instruct FFmpeg to extract frames at this rate regardless of the video's frame rate
      .fps(frameRate)

      // Save frames to this directory
      .saveToFile(outputFilepath)

      .on('end', () => resolve())
      .on('error', (error) => reject(new Error(error)));
  });
}
umaar commented 1 year ago

Thanks, that works!