I'm having trouble muxing the video from one source with the audio from another because the audio drifts over time. As I mentioned in the title, the sources are at different frame rates, the video's source is at 23.976, and the audio's source is at 29.97.

Maybe my current code will help to better understand the situation:

ffmpeg -y -i source1.mkv -itsoffset 0.85 -i source2.mp4 -map 0:0 -map 1:1 -c:v libx264 -crf 23 -c:a aac -b:a 112k output.mp4

The audio source's audio starts a bit early, hence the 0.85 second delay.

I'm using FFmpeg version: 20170904-6cadbb1

  • 1
    The (originally paired) video's framerate does not apply to the audio. You'll probably have to rescale the external audio. Check the stream durations: ffprobe file -show_streams – Gyan Sep 8 '17 at 9:18
  • Yeah I understand that audio doesn't work in frame rates but that doesn't explain why it goes out of sync. I tried slowing down the audio by matching its length to the video source's with the atempo audio filter, but it doesn't really work due to the offset. – Rapta Sep 8 '17 at 13:59
  • Try scaling to audio length = video length - offset and mux with the offset. This assumes that the drift is linear. – Gyan Sep 8 '17 at 14:41
  • You mean to input into atempo the value of the video source's length minus the 0.85s offset, but to also include the offset in the code? so ffmpeg -y -i videosource.mkv -itsoffset 0.85 -i audiosource.aac -map 0:0 -map 1:0 -af atempo=(video source's length - the offset) / video source's length -c:v libx264 -crf 23 out.mp4? If so, it didn't work. – Rapta Sep 8 '17 at 15:12
  • atempo = oldaudiolength / newaudiolength where new length is video stream's length - the offset. – Gyan Sep 8 '17 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.