0

I am mixing an MP4 file with a WAV file. The MP4 contains both audio and video. Basically the mp4 is a video of someone singing to a beat. The WAV file contains the beat.

In the resultant file the WAV file is slightly behind the MP4 file. If possible I don't want to trim the WAV file at the start in order to bring it forward, I would much rather add a delay to the MP4 (both audio and video in the MP4) so that the resultant file is all sync'd up. I cannot do any manual steps as I am doing this programatically from within an app.

Here is my current command, it mixes the MP4 and the WAV and uses a filter to manipulate the volume levels

-i /home/video/file.mp4 -i /home/music/beat.wav -preset veryfast -crf 32 -filter_complex [0:a:0]volume=0.5[fa];[1:a:0]volume=0.5[fb];[fa][fb]amix=inputs=2:duration=first[fc] -map [fc] -map 0:v:0 -c:v copy -shortest

1 Answer 1

1

Add an offset to the MP4. Use aresample to plug the gap in the audio due to the offset. The video will appear frozen for offset amount of time at the start.

-itsoffset 0.5 -i /home/video/file.mp4 -i /home/music/beat.wav -filter_complex "[0:a:0]aresample=async=1:first_pts=0,volume=0.5[fa];[1:a:0]volume=0.5[fb];[fa][fb]amix=inputs=2:duration=first[fc]" -map [fc] -map 0:v:0 -preset veryfast -crf 32 -c:v copy -shortest

6
  • This command runs successfully however adding the itsoffset argument doesnt help to synchronize the mp4 with the wav. the playback is the same. the only thing i noticed that is different is when I played the resultant video back, my video player seekbar was on 'offset' seconds. For example if i do 'itsofset 2', then the video playing software seekbar is on the 2 second mark when the file opens, but when it plays it seems exactly the same as when the itsoffset parameter isnt included in the command
    – brux
    Feb 25, 2020 at 16:50
  • Which player? ..
    – Gyan
    Feb 25, 2020 at 16:55
  • Both the Ubuntu stock video player and VLC in ubuntu.
    – brux
    Feb 25, 2020 at 17:26
  • In case you could take a look at my source files here is the mp4 and the wav compressed into a zip file we.tl/t-TnEnPQJtEn
    – brux
    Feb 25, 2020 at 17:28
  • 1
    Edited cmd.....
    – Gyan
    Feb 25, 2020 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .