FFMPEG resyncing audio

I have a video file with 2 audio streams the 2nd audio stream is out of sync How can I use FFMPEG to fix this? All suggestions welcome, Thanks in advance!
15 Replies
HunterAP
HunterAP15mo ago
It depends - is the audio ahead of the video, or is the video ahead of the audio? And by how much? If the audio is coming in before the video, then you would need a command like this: ffmpeg -i "YOUR_INPUT_FILE" -itsoffset SS.MS -i "YOUR_INPUT_FILE" -map 1:v -map 0:a -c copy "OUTPUT_FILE" Otherwise if the audio is coming after where it should in the video, then you would need a command like this to delay the video stream ffmpeg -i "YOUR_INPUT_FILE" -itsoffset SS.MS -i "YOUR_INPUT_FILE" -map 0:v -map 1:a -c copy "OUTPUT_FILE" replace SS.MS with the seconds and milliseconds of delay you want to apply
BrainZ
BrainZOP15mo ago
2nd audio stream has a delay of 716.67ms or 43 frames so it needs to start earlier OR have the Video Stream + Audio Stream 1 delayed by that same amount of time will play around with what you have given me already! Thanks 🙂
HunterAP
HunterAP15mo ago
Then you'll want to run this command ffmpeg -i "YOUR_INPUT_FILE" -itsoffset 0.7167 -i "YOUR_INPUT_FILE" -map 0:v -map 1:a -c copy "OUTPUT_FILE"
BrainZ
BrainZOP15mo ago
OK I tried it but that just delayed the audio for audio stream 1
HunterAP
HunterAP15mo ago
Oh my mistake, it should be this instead: ffmpeg -i "YOUR_INPUT_FILE" -itsoffset 0.7167 -i "YOUR_INPUT_FILE" -map 0:v -map 1:a:1 -c copy "OUTPUT_FILE" The change here is from -map 1:a to -map 1:a:1 to specify the 2nd audio source instead of the first one (which would be -map 1:a:0)
BrainZ
BrainZOP15mo ago
Hmmmmm now there is no audio from audio stream 1 and Audio stream 2 is now even more delayed I'm starting to wonder if it is even possible at all? I appreciate your suggestions btw!
HunterAP
HunterAP15mo ago
I think we just miscommunicated ffmpeg -i "YOUR_INPUT_FILE" -itsoffset 0.7167 -i "YOUR_INPUT_FILE" -map 1:v -map 0:a:1 -c copy "OUTPUT_FILE"
BrainZ
BrainZOP15mo ago
OK so now Audio Stream 2 is in sync with the Video but there is now Audio from Audio stream 1
BrainZ
BrainZOP15mo ago
No description
BrainZ
BrainZOP15mo ago
for a litle more context
HunterAP
HunterAP15mo ago
hmmm ffmpeg -i "YOUR_INPUT_FILE" -itsoffset 0.7167 -i "YOUR_INPUT_FILE" -map 1:v -map 1:a:0 -map 0:a:1 -c copy "OUTPUT_FILE" there
BrainZ
BrainZOP15mo ago
You sir, are an absolute genius.
MEE6
MEE615mo ago
GG @brainz26, you just advanced to level 7 !
BrainZ
BrainZOP15mo ago
It works perfectly now thank you so much! you have potentially saved me hours and hours of time now haha honestly really appreciate it this has been something I've attemtped on and off now for months lol
HunterAP
HunterAP15mo ago
Glad I could help!

Did you find this page helpful?