ffmpeg - correctly handling misaligned audio/video input stream before outputting to rtmp

287 Views Asked by At

I use a video player called MPV to transcode a dynamic playlist of media files.

I pipe MPV's encoded output into FFMPEG and format it for rtmp delivery.

However the playlist may contain media with misaligned audio and video, ie - the audio track may be shorter / longer than the video track.

No matter what MPV will only output what it's given. So if my media file has audio that is 1 second long and video that is 2 seconds long, it will output a media stream with exactly the same misalignment, rather than generating null audio or skipping to the next item in the playlist when it first encounters an active stream ending (eof).

For example, assuming my playlist was full of problematic media where the audio and video of each file was misaligned:

enter image description here

If I output this media stream to a popular streaming service's server, it could lead to stuttering and/or loss of a/v sync. Similarly, if I output this media stream to a file and played it back in MPV or another video player, the result appears to be more like this:

enter image description here

I have tried to fix this in MPV in all sorts of ways, trying every relevant command line option available. I even wrote a user script that detects 'eof' audio and skips to the next item in the playlist, but it is not fast enough and still leads to small gaps of audio.

So my only hope is correcting it in ffmpeg. In the event of null audio/video, I need a fallback or a generative filter that can fill these empty gaps with silence (audio) or a colour/image (video).

I'm open to any ideas, and if my understanding in a/v encoding is a little off please educate me.

0

There are 0 best solutions below