简体   繁体   English

AWS ffmpeg-lambda-layer 和 concat 协议 (Node.js)

[英]AWS ffmpeg-lambda-layer and concat protocol (Node.js)

I am trying to concatenate two.mp3 files using ffmpeg lambda-layer.我正在尝试使用 ffmpeg lambda 层连接两个.mp3 文件。 I have what I think is the correct command, but I struggle to represent it in code so that it is formatted correctly for the lambda layer.我有我认为正确的命令,但我很难用代码表示它,以便它为 lambda 层正确格式化。 Here is a piece of code that I am struggling to get right:这是一段我正在努力纠正的代码:

spawnSync(
  '/opt/ffmpeg/ffmpeg',
  [
    '-i',
    '"concat:/tmp/pt1.mp3|/tmp/pt2.mp3"',
    '-acodec',
    'copy',
    `/tmp/${fileName}`
  ],
  { stdio: 'inherit' }
)

The error I'm getting: "concat:/tmp/pt1.mp3|/tmp/pt2.mp3": No such file or directory .我得到的错误: "concat:/tmp/pt1.mp3|/tmp/pt2.mp3": No such file or directory

I tried to list files in /tmp/ folder - both files listed in the input are there, not sure why lambda layer can't find them.我试图列出/tmp/文件夹中的文件 - 输入中列出的两个文件都在那里,不知道为什么 lambda 层找不到它们。

Similar question: https://lists.ffmpeg.org/pipermail/ffmpeg-user/2019-December/046299.html .类似的问题: https://lists.ffmpeg.org/pipermail/ffmpeg-user/2019-December/046299.ZFC35FDC70D5FC69D269883A822C7A53 Ffmpeg concatenate protocol documentation: https://trac.ffmpeg.org/wiki/Concatenate#protocol . Ffmpeg 连接协议文档: https://trac.ffmpeg.org/wiki/Concatenate#protocol

Thanks in advance!提前致谢!

Update: Was able to solve this by using concat demuxer istead of concat protocol.更新:能够通过使用 concat demuxer 而不是 concat 协议来解决这个问题。 Docs: https://trac.ffmpeg.org/wiki/Concatenate#demuxer文档: https://trac.ffmpeg.org/wiki/Concatenate#demuxer

It requires.txt file with the list of input files so I had to create one.它需要带有输入文件列表的 .txt 文件,所以我必须创建一个。 Here is my solution:这是我的解决方案:

// in the head of the file
const { writeFile } = require('fs')
const { promisify } = require('util')

const asyncWriteFile = promisify(writeFile)

// ...

await asyncWriteFile('/tmp/list.txt', 'file \'/tmp/pt1.mp3\'\r\nfile \'/tmp/pt2.mp3\'', (err) => {
 if (err)
  console.log(err)
})

// concat
spawnSync(
 '/opt/ffmpeg/ffmpeg',
 [
   '-f',
   'concat',
   '-safe',
   '0',
   '-i',
   '/tmp/list.txt',
   '-c',
   'copy',
   `/tmp/${fileName}`
  ],
  { stdio: 'inherit' }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM