I have an application that handles the normalizing and combining of audio and video files from many different sources.
All incoming audio is normalized as follows:
ffmpeg.exe -i "PathToIncommingAudioFile" -acodec aac -ac 2 -ar 44100 -ab 128k -strict experimental ""outputFile.aac"
All incoming video is normalized as follows:
ffmpeg.exe -i "PathToIncommingAudioFile" -s 852x480 -r 30 -aspect 1.775 -b:v 2000000 -vcodec mpeg4 -vf ""scale=iw*min(852/iw\,480 /ih):ih*min(852/iw\,480 /ih),pad=852:480 :(852-iw)/2:(480 -ih)/2"" -acodec aac -ac 2 -b:a 128k -ar 44100 -strict experimental "outputFile.mp4"
Each of these commands (please forgive any bad practices, this is not my area of expertise) works for normalizing the media so it can be played across devices.
Other code allows us to successfully merge audio to audio and video to video. However when I attempt to merge the two, the audio gets out of sync.
Here is what I'm doing:
First the audio is converted to a video file using a simple PNG image as a placard
ffmpeg.exe -loop 1 -shortest -i "image.png" -i "normalized.aac" -s 852x450 -r 30 -aspect 1.775 -b:v 2000000 -vcodec mpeg4 -acodec aac -ac 2 -b:a 128k -ar 44100 -strict experimental "audioAsVideo.mp4"
Next the videos are attempted to be merged the same way that normally works. (A solution with ffmpeg was not found and this is what currently works, in most cases)
mp4box.exe -cat "audioAsVideo.mp4" -cat "normalizedVideo.mp4" -new "CombinedVideo.mp4"
Next to handle some videos that only have one channel audio (like webcams) the following hack/fix was added. It runs on all video to video combines and usually works
ffmpeg.exe -i "CombinedVideo.mp4" -c copy -ac 1 "SingleChannelCombinedVideo.mp4"
If this process is done with an audio and a video, the audio sync of the second file is off. If this is the audio over the placard it is not a big deal. But if it is the video, it is very distracting.
- Does anyone see anything I have done that could cause this?
- An idea on what to change?
- Perhaps a way of butting a buffer in between the two that would force the sync back?
- A better way of doing it?