kxmovie
kxmovie copied to clipboard
FLV audio sync issue when streaming via TCP
Hi Kolyvan, this is a wonderful project. I'm no expert with ffmpeg so I'm not exactly sure what should be done to fix an audio/video sync issue I have when I try to play streamed content. It only happens when streamed, otherwise playing the FLV file locally presents no issues.
To reproduce the error, you can add
tcp://<your device's local IP>:<some port>/?listen
to the list of URLs in your KxMovieExample project.
Then, when you open that URL, you can do in your mac/linux machine via command line:
curl http://eric.cast.ro/stream2.flv | nc <your device's local IP> <some port>
The example FLV in my website illustrates very quickly the problem through a wrong lip sync. Requires curl and netcat installed, which can be obtained via MacPorts.
Or, if your device is jailbroken, you can execute the exact same command (but change nc to netcat) via SSH after installing those same command utilities via Cydia
Any help is greatly appreciated!
I just noticed you can also reproduce this same problem without necessarily doing so via a live TCP stream.
If you open the FLV locally, the first run will sync fine, but if you rewind/fast forward, the audio will get out of sync just like when streaming.
I am able to fix the sync issue if I change the delta limits in lines 881 and 820 in KxMovieViewController.m, instead of allowing 2 seconds I reduce it to 0.02 seconds.
This way my video gets synced correctly but I am afraid I might have broken something else? Why was 2 second delta allowed before correcting sync issues ? isn't that a lot ?
I kindly wait for your input on this.
There are many possible reasons for audio desync.
- problem with resampling. The native audio sample rate for iphone is 44100Hz but lots of movies has 48kHz audio streams. And it is quite possible what or resampling or bugs here causes audio lags.
- The problem with estimating of audio frame timestamp. It's heuristics process and could return a incorrect result too. And in general, the bugs of current frame timing algorithm may cause desyning.
- The possible bugs in implemetation of audio unit render callbacks can be cause of lags.
- And the movie file itself can contain desynced video and audio streams. Or may contains broken (undecoded) frames.
- Due to chunked nature of movie files, the rewind/forward may cause desyncing of audio and video streams.
- The network stream may lose or contain damaged audio/video packets.
So I have not a simple solutions. I plan to spend some time and maybe fix some lags. But for now I unable to completely remove cause of lags.
Why was 2 second delta allowed before correcting sync issues ?
It's tunable parameter. And feel free to change it as need in your case.
Look at commit 84587d3f29bdc741ee3382035bfe3759bbd0d10a I did a some changes for more correct timing.
Thanks for your reply. The applied changes don't fix the problem. The results also vary when running on iPad or iPad Simulator.
On the iPad I reduce the delta allowed to a number like 0.05 seconds, and audio syncs fine, almost no outruns/skips
On the simulator I am not very sure what to try as a higher number allows too much desync while a reduced number like 0.05 produces too many outruns.
I understand all possible causes you mention, and in fact the FLV I am using to test is recorded from a live RTMP stream, so it is very likely that it might have corrupted / damaged bits or not have a correct timing format as the FLV structure is built on the fly without having a proper termination - since it's a live stream.
I will keep playing around with this, I am getting a little used to the code and ffmpeg itself so I'll be glad if I can make any contribution some time later :)
Keep me posted if you make any further corrections! Thanks again!
i also find this problem , also in ipad, and play mp4 http file .
how to resolve this problem??
not only the first open ,this problem appear, when play long time , it also show video and audio not sync
It will be nice if you could share the link which causes audio sync issue so I can observe it myself.
http://f.youku.com/player/getFlvPath/sid/136670091323688_01/st/mp4/fileid/0300080E00511FD64A599602996C24A7280AF1-F416-A15B-9AE5-614DB8D020B6?K=f13804a8093ffa9d241160e5&hd=1
and use kxmovie open it, and see some moment on ipad, and you will find the audio does not sync with the video
Sorry, but your link is broken: 404 Not Found,
i'm sorry, it has been unavailable, now ,use this: http://m.youku.com/smartphone/pvs?vid=XMzY4MTk0NzAw&format=3gphd&cid=100&stat_down_=1
Yes, I noticed some audio glitches. Sorry, But now I don't know what is the cause of them .
thanks , when can you fix it?
Any update on this issue? I'm also seeing a sync issue between audio and video.
Any update on this issue now?
hi,when i use it to play "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov",it will stop at the last two seconds,so i can't know the right time to play the next