ffmpeg在AWS Lamda函数中返回错误代码1 [英] Ffmpeg returning error code 1 in AWS Lamda function

查看:79
本文介绍了ffmpeg在AWS Lamda函数中返回错误代码1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个lambda函数,该函数需要一个 mp4 视频,并在其右下角的顶部上方添加 png 图像的水印(边距为 10px ).然后,它将图像输出到一个临时位置.它始终会失败,并显示 Error code 1 (错误代码1),但这不是很有帮助.我使用的是在代码主目录中指定的 ffmpeg 二进制版本.我知道 ffmpeg 的设置正确,是因为以这种方式在另一个lambda函数中使用了它,因此可以正常工作.但是添加覆盖失败.这是我的代码的相关部分:

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?

更新

我设法打印出更多日志,但出现错误:

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'

推荐答案

您必须使用 -f格式选项告诉ffmpeg您希望输出什么格式.运行 ffmpeg -formats 以获得支持的格式列表.

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.

ffmpeg文档:

-f fmt(输入/输出)强制输入或输出文件格式.通常会自动检测输入文件的格式,并根据输出文件的文件扩展名猜测格式,因此在大多数情况下不需要此选项.

-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.

例如,如果您希望输出为MPEG-4,则对ffmpeg的调用应如下所示:

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"
   ]);

这篇关于ffmpeg在AWS Lamda函数中返回错误代码1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆