Saving mp4 stream causes audio/video to go progressively more out of sync

About encoding, codec settings, muxers and filter usage
selulven
New Cone
New Cone
Posts: 3
Joined: 05 May 2016 20:42

Saving mp4 stream causes audio/video to go progressively more out of sync

Postby selulven » 05 May 2016 20:56

Hi,

I'm trying to download TV shows that are published online by the broadcaster. The shows are meant for streaming, so you get an m3u8 file to play from. With vlc, I save this stream to disk using either the GUI (Convert/Save) or the command line (--sout #std{access=file,dst=...} without transcoding. This is the stream information for the resulting file:

Video: MPEG4 Video (H264) 1280x720 25fps 2230kbps [V: English [eng] (h264 high L4.1, yuv420p, 1280x720, 2230 kb/s)]
Audio: AAC 48000Hz stereo 157kbps [A: SoundHandler [eng] (aac, 48000 Hz, stereo, 157 kb/s)]

Both methods cause the same audio/video sync issues that are NOT present when I transcode the stream (to vcodec=mp4v,acodec=mpga,deinterlace) on the fly before sending it to a file.

I'm curious as to why it happens, but more importantly I wonder if there's any way I can fix this after the fact. Entering a fixed sync offset will not help and transcoding the saved stream does not fix the issue the same way it does when transcoding is done on the fly. Transcoding with audio-sync after the stream has been saved doesn't help either.

Any suggestions?

kmf31
Cone that earned his stripes
Cone that earned his stripes
Posts: 308
Joined: 11 Mar 2007 21:47

Re: Saving mp4 stream causes audio/video to go progressively more out of sync

Postby kmf31 » 05 May 2016 21:07

Which "mux" are you using when direct saving (with #std) ? I suppose you use "mp4" ?
Did you try to save in "ts", i.d. with --sout=#std{mux=ts,...} ?

If this works you can also try after this to transcode (or save a second time) the file to something else.

selulven
New Cone
New Cone
Posts: 3
Joined: 05 May 2016 20:42

Re: Saving mp4 stream causes audio/video to go progressively more out of sync

Postby selulven » 05 May 2016 23:09

Hi kmf31, thanks for replying.
Which "mux" are you using when direct saving (with #std) ? I suppose you use "mp4" ?
I didn't specify mux and didn't even think about it. But I just tried, and the results are:

without mux -- video freezes for a fraction of a second while audio is playing at the very beginning of the video, but is in sync once it starts and then progressively goes more and more out of sync

with mux=mp4 -- same result as without mux
Did you try to save in "ts", i.d. with --sout=#std{mux=ts,...} ?
with mux=ts -- video freezes for two seconds at the beginning while audio is playing, and if you skip to a different time it will also freeze for a significant time while audio is playing. It looks like it freezes while waiting for an I-frame. Audio and video are in sync at all times.
If this works you can also try after this to transcode (or save a second time) the file to something else.
I can't save them again since they've become unavailable since I downloaded them. Which is why I'm looking for a way to resolve this after the fact.

kmf31
Cone that earned his stripes
Cone that earned his stripes
Posts: 308
Joined: 11 Mar 2007 21:47

Re: Saving mp4 stream causes audio/video to go progressively more out of sync

Postby kmf31 » 06 May 2016 18:50

I am not sure if you can easily repair once it is saved. The best thing would be to save from the very beginning in ts and then apply transcoding in mp4. I believe when you save first in ts vlc does some "useful" things on the time stamps etc. good for the synchronisation provided that the initial flux is not buggy. Furthermore in ts you can rather easily keep all audio- and subtitle tracks which are initially present in the flux (at least if the original flux is digital TV).

If the file freezes with vlc you may try to increase caching values, e.g. --file-caching=2000 (for 2000 ms, or even more if necessary).

selulven
New Cone
New Cone
Posts: 3
Joined: 05 May 2016 20:42

Re: Saving mp4 stream causes audio/video to go progressively more out of sync

Postby selulven » 09 May 2016 08:58

It's really odd, because if I transcode to mp4 (from the raw mp4 stream) directly when saving, the audio is in sync. So it seems anything that requires vlc do to something other than just dump the raw stream, will fix the problem.

But if there's no way to fix this once it's gone wrong, I'll just have to wait until the series become available again.

Thanks for your time.

Hubalaga
New Cone
New Cone
Posts: 1
Joined: 05 Jan 2019 16:59

Re: Saving mp4 stream causes audio/video to go progressively more out of sync

Postby Hubalaga » 05 Jan 2019 17:03

Try this:

:sout=#file{mux=ts,dst=C:\\temp\\test3.mp4,no-overwrite} :no-sout-all :sout-keep :sync-audio


Return to “VLC stream-output (sout)”

Who is online

Users browsing this forum: No registered users and 25 guests