0

I use ffmpeg to transcode videos in a express application. I've a test script that transcode the same file, when I call the endpoint that start the script multiple times (2/3 time simultaneously) randomly one of that transcoded file is end up to be corrupted, seems that ffmpeg close the transcoding before it's finished, someone has experienced the same problem? In local doesn't happen.

I use fluent-ffmpeg with libx264 coded.

Edited:

async function resizeVideo(srcKey, dstKey) {
  return new Promise((resolve, reject) => {
    let quality = 720;
    let command = new FFmpeg({ source: "./tmp/"+srcKey })
    .addOptions(['-codec:v', 'libx264', '-profile:v', 'main', '-preset', 'fast', '-b:v', '2M', '-maxrate', '2M', '-bufsize', '1M', '-vf', `scale=-2:${quality}`, '-threads', '0', '-b:a', '128k'])
    .on('error', function(err) {
        reject(false);
    })
    .on('end', function() {
        resolve(true);
    })
    .saveToFile("./tmp/"+dstKey);
  })
}

tnx

red
  • 1,529
  • 1
  • 12
  • 33
  • Code or it didn't happen. – robertklep Sep 02 '22 at 17:01
  • you're right, edited! – red Sep 02 '22 at 17:29
  • Are you sure that you're not overwriting the same file with each request? In other words, is `dstKey` different every time? Also, since you're using `-threads 0`, one transcode session might take up all your CPU resources and starting more than one at a time could cause CPU starvation issues. – robertklep Sep 02 '22 at 17:35
  • tnx @robertklep, dstKey is different each time, tested with -threads 1, same problem. – red Sep 02 '22 at 17:52

0 Answers0