I am trying to concatenate two.mp3 files using ffmpeg lambda-layer. 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. 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
.
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.
Similar question: https://lists.ffmpeg.org/pipermail/ffmpeg-user/2019-December/046299.html . Ffmpeg concatenate protocol documentation: https://trac.ffmpeg.org/wiki/Concatenate#protocol .
Thanks in advance!
Update: Was able to solve this by using concat demuxer istead of concat protocol. Docs: https://trac.ffmpeg.org/wiki/Concatenate#demuxer
It requires.txt file with the list of input files so I had to create one. 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' }
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.