spartaslave
spartaslave

Reputation: 125

how to use command line to stitch two wav together using ffmpeg in linux?

I have installed ffmpeg on debian and I tried the two command lines. There are two files under the same directory, they are first.wav and second.wav The first method is to create a txt file, inside a.txt, they are

file 'first.wav'
file 'second.wav'

I have run

ffmpeg -f concat -i a.txt -c copy final.wav

then I run it, it could work fine. But I want to try another method, which is

ffmpeg -i "concat:first.wav|second.wav" -c copy final2.wav

there is not error with the sdcond command line, but it only capture the first file and the length of final2.wav is almost same as first.wav. File second.wav is not stitched at all. As I am using golang to execute the command line, I want to use

cmd := exec.Command("ffmpeg",args)

to stitch the medias together, I can read all the media files into an array, but this API cannot work for the array, so I want to stitch the files together to

"concat:file1.wav|file2.wav|file3.wav|......"

in this case it could be easy to stitch the files together and I do not need to loop the cmd. like

cmd = exec.Command("ffmpeg","-i","concat:first.wav|second.wav|third.wav|......","-c","copy","final2.wav")

I do not want to create any extra files like a.txt file as I need to delete it later and this may also touch the permission. So is there any possible solution for the second command line?

Upvotes: 1

Views: 902

Answers (1)

Leon
Leon

Reputation: 348

Try this one

ffmpeg -i 1.wav -i 2.wav -i 3.wav ...... -i {n}.wav -filter_complex '[0:0][1:0]......[{n-1}:0]concat=n={n}:v=0:a=1[out]' -map '[out]' final.wav

Upvotes: 2

Related Questions