2

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:

  1. 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"
    
  2. 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"
    
  3. 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?
3
  • @slhck wouldnt that replace the audio from the video with the new audio? I am not trying to replace any audio just concatenate them, and if one is an audio add a placecard.
    – Bill Bonar
    Dec 11, 2012 at 21:21
  • Any reason you're using MPEG-4 Visual video (mpeg4 in FFmpeg) and not H.264 (-c:v libx264 in FFmpeg)? So, am I correct that CombinedVideo shows the out-of-sync errors?
    – slhck
    Dec 11, 2012 at 21:33
  • At the creation of this feature, i believe it was chosen for compatibility with older devices. I was not involved in that choice. Yes you are correct CombinedVideo shows the out of sync error
    – Bill Bonar
    Dec 13, 2012 at 14:36

0

You must log in to answer this question.

Browse other questions tagged .