Advice on audio replacement please

Started by AlanD, January 29, 2020, 01:45:50 AM

Previous topic - Next topic

AlanD

Sometimes I have shot some video on an action cam, great video, awful sound, and recorded sound separately on a high-quality stereo recorder. My normal procedure would be

- load video into AVIdemux, trim to the correct length, and save as MP4
- load MP4 into Audacity
- load WAV file from recorder into Audacity.
- adjust position of WAV file until it is exact match to video, and trim to correct start and length
- export trimmed WAV file as new audio soundtrack
- use AVIdemux to replace action-cam soundtrack with correctly-trimmed high-quality version

This usally works fine but sometimes I still end up with noticeable synch errors, maybe just a tenth of a second, but enough to be noticed when people are talking. It is much more apparent with MP3, and my understanding of the problem is that MP3 files contain a variable length header of metadata. It appears to me that when Audacity saves an MP3 file, it adds the metadata header, but when AVIdemux replaces an audio track, it doesn't take the length of the MP3 header into account and that this creates a synch error.  My various MP3 players don't play any strange clicks or anything at the start of such tracks, so they are able to identify how long this non-audio data is, and how much they need to skip over. I thought using WAV avoided this problem, but I still think I sometimes get small synch errors with WAV too, but I cannot be certain on that.

So, questions arising from this are:

1) Is there an oversight in the audio track code of AVIdemux, where it should be taking non-audio metadata into account when using external audio tracks?

2) Is there an AVIdemux setting somewhere that I am missing?

3) Failing that, if I know that the audio file I've saved has an additional 0.15s worth of non-audio metadata on the front, I can presumably fix that with an audioshift of 150mS, but should I be using a positive shift or a negative shift? Remember the audio is lagging behind the video, so which direction fixes that in an AVIdemux shift.

4) Can anyone suggest the best audio format to use for compatibility with AVIdemux? i.e. any format where I wouldn't get this synch problem? Or even if anyone knows of settings in Audacity which fixes this for any of the audio formats?

eumagga0x2a

If you look into Avidemux log after you added an external audio track from a MP3 file with id3 metadata, you will find an entry like

[create_edAudioExternal] 22:42:16-683  Found external audio track, encoding =85 offset=576

Doing the same using an MP3 file with metadata stripped, you will find this entry with offset being equal zero (I refer as always to the current git master). I think we handle metadata related offset correctly.

What is probably missing when adding an external audio track, it is all info from MP4 edit lists (the 'elst' box). Another source of sync loss might be the presence of B-frames in the video as Avidemux will automatically delay internal tracks to account for a non-zero PTS of the first video frame. I'm not sure this applies to external tracks as well. If external audio is ahead of the video, this might be the case.

Regarding audio shift, positive values delay audio, negative values delay video.

I don't think the loss of sync has anything to do with codec of the external audio track, but it may be related to the container holding the source video.