sheodox
sheodox

Reputation: 835

How to play video Media Source Extensions when the audio start is delayed? Or how to fix it with ffmpeg?

I have a video that I'm splitting the individual video/audio streams out then dashing with MP4Box, then I'm playing them with Media Source Extensions and appending byte ranges to video/audio source buffers from the MPD files. It's all working nicely, but one video I have has audio that is delayed by about 1.1 second. I couldn't get it to sync up and the audio would always play ahead of the video.

Currently I'm trying to set the audioBuffer.timestampOffset = 1.1 and that gets it to sync up perfectly. The issue I'm running into now though is the video refuses to play unless the audio source buffer has data. So the video stalls right away. If I skip a few seconds in (past the offset) everything works because both video/audio are buffered.

Is there a way to get around this? Either make it play without the audio loaded, somehow fill the audio buffer with silence (can I generate something with the Web Audio API)? Add silence to the audio file in ffmpeg? Something else?

I first tried adding a delay in ffmpeg with ffmpeg -i video.mkv -map 0:a:0 -acodec aac -af "adelay=1.1s:all=true" out.aac but nothing seemed to change. Was I doing something wrong? Is there a better way to demux audio while keeping the exact same timing as when it was in the container with the video so I don't have to worry about delays/offsets at all?

Upvotes: -1

Views: 447

Answers (1)

sheodox
sheodox

Reputation: 835

I managed to fix it with ffmpeg using -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" which was mentioned in this article https://videoblerg.wordpress.com/2017/11/10/ffmpeg-and-how-to-use-it-wrong/

Upvotes: 0

Related Questions