Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mix Audio tracks with offset in SOX

From ASP.Net, I am using FFMPEG to convert flv files on a Flash Media Server to wavs that I need to mix into a single MP3 file. I originally attempted this entirely with FFMPEG but eventually gave up on the mixing step because I don't believe it it possible to combine audio only tracks into a single result file. I would love to be wrong.

I am now using FFMPEG to access the FLV files and extract the audio track to wav so that SOX can mix them. The problem is that I must offset one of the audio tracks by a few seconds so that they are synchronized. Each file is one half of a conversation between a student and a teacher. For example teacher.wav might need to begin 3.3 seconds after student.wav. I can only figure out how to mix the files with SOX where both tracks begin at the same time.

My best attempt at this point is:

ffmpeg -y -i rtmp://server/appName/instance/student.flv -ac 1 student.wav 
ffmpeg -y -i rtmp://server/appName/instance/teacher.flv -ac 1 teacher.wav 

sox -m student.wav teacher.wav combined.mp3 splice 3.3

These tools (FFMEG/SoX) were chosen based on my best research, but are not required. Any working solution would allow an ASP.Net service to input the two FMS flvs and create a combined MP3 using open-source or free tools.

EDIT: I was able to offset the files using the delay switch in SOX.

sox -M student.wav teacher.wav combined.mp3 delay 2.8

I'm leaving the question open in case someone has a better approach than the combined FFMPEG/SOX solution.

like image 586
Laramie Avatar asked Nov 14 '22 04:11

Laramie


1 Answers

For what it's worth, this should be possible with a combination of -itsoffset and the amix filter, but a bug with -itsoffset prevents it. If it worked, the command would look something like this:

ffmpeg -i student.flv -itsoffset 3.3 -i teacher.flv -vn -filter_complex amix out.mp3
like image 180
blahdiblah Avatar answered Dec 18 '22 13:12

blahdiblah