Ffmpeg returning error code 1 in AWS Lamda function

浪尽此生 提交于 2021-01-28 06:53:15

问题


I'm running a lambda function which takes an mp4 video, and adds a watermark of a png image over the top of it in the bottom right hand corner (with a 10px margin). It then outputs that image to a temporary location. It keeps failing with Error code 1, but that isn't very helpful. I'm using a binary version of ffmpeg that is specified in the main directory of the code. I know that ffmpeg is set up correctly due to using it in another lambda function in this way, which works. But adding an overlay fails. Here is the relevant part of my code:

function addWatermark(next) {
    var ffmpeg = child_process.spawn("ffmpeg", [
      "-i", target, // url to stream from
      "-i", watermarkPath,
      "-filter_complex" ,"overlay=x=W-w-10:y=H-h-10:format=rgb,format=yuv420p",
      "-c:a", "copy",
      "pipe:1"
    ]);
    ffmpeg.on("error", function(err) {
      console.log(err);
    })
    ffmpeg.on("close", function(code) {
      if (code != 0 ) {
        console.log("child process exited with code " + code); // Always exits here.
      } else {
        console.log("Processing finished !");
      }
      tmpFile.end(); 
      next(code);
    });
    tmpFile.on("error", function(err) {
      console.log("stream err: ", err);
    });
    ffmpeg.on("end", function() {
      tmpFile.end();  
    })
    ffmpeg.stdout.pipe(tmpFile)
    .on("error", function(err){
      console.log("error while writing: ",err);
    });
}

Can anyone spot what may be wrong?

UPDATE

I've managed to print out some more logs, I'm getting the error:

[NULL @ 0x42923e0] Unable to find a suitable output format for 'pipe:1'

回答1:


You have to tell ffmpeg what format you want the output in using the -f format option. Run ffmpeg -formats to get the list of supported formats.

From the ffmpeg documentation:

-f fmt (input/output) Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

For example, if you want the output as MPEG-4, then your call to ffmpeg should look like this:

   var ffmpeg = child_process.spawn("ffmpeg", [
     "-i", target, // url to stream from
     "-i", watermarkPath,
     "-filter_complex" ,"overlay=x=W-w-10:y=H-h-10:format=rgb,format=yuv420p",
     "-c:a", "copy",
     "-f", "m4v",
     "pipe:1"
   ]);


来源:https://stackoverflow.com/questions/49797534/ffmpeg-returning-error-code-1-in-aws-lamda-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!