-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delay when play rtsp stream from network camera #42
Comments
I don't feel comfortable changing those lines without understanding the reason. I think your issues comes from another side. Rtsp falsely reports that it has audio/sound while it doesn't so it waits for audio to come up before playing. To ensure that the issue is that try to change this line / boolean to true Flyleaf/FlyleafLib/MediaPlayer/Player.cs Line 724 in 05c307b
|
Is it possible that the delay is coming randomly sometimes from the camera? I can't see the issue with the code there. The only thing that have in mind is possible that you open a lot of threads (players) and takes too long to create a new thread? |
I think I have seen something similar in the past. With network streams, without any reason the demuxer is 'relaxing' and i thought the issue was from the other side. Additionally, the fix code that you propose doesn't make sense if that's the issue. I will have a look but not sure what I should check yet. |
yes, My purpose is reduce some Thread.Sleep(xxx) in your code, and want to thread start immediate. May be the reason is because you separate to demux thread and decode thread, so each thread will have to wait for each other (buffering). |
I'm sure that this Thread.Sleep is not an issue and it's only once until the thread it comes up (it could probably be about 5-10ms max). Demux / Decode run on different thread and that makes it faster, Of course Decode should wait to have demuxed packets though. Still can't see any delay 1-2 seconds that you mention in the logs anywhere. Did you try to reduce the MinVideoFrames to reduce the buffering time? |
setting player.Config.decoder.MinVideoFrames = 1 but same result. for compare, you can access that camera on internet explorer (require install activeX): |
There is one more problem that I am still confused: I am only run your demo program on my PC: I am test with some VMS software for ip camera before as Milestone or https://eocortex.com/, or NUUO Mainconsole https://www.nuuo.com/.... |
Decoder frames are related with the demuxer packets. If you don't have enough MaxQueueSize (demuxed packets) you will never reach the 100 video frames. The decoded videos frames queue are the frames ready to be rendered. Probably in your case with the default MaxQueueSize = 200 demuxed packets you can get 26 videos frames (the rest packets can be audio or other data). I didn't understand the second part of you question. Generally, if the pc cannot handle the cpu/gpu for the playback you could drop frames (in case of rendering/gpu) but for the decoding you cannot do much (cpu). Even with buffering you cannot hold too many frames in memory, they are huge usually. |
I mean: my PC is powerful enough to decode and display in realtime video stream of this camera (1280x960, 10fps). Please test rtsp url from message above. |
Full buffer means fast pc. The rtsp url that you say, I don't even get the frames right. I get previous timestamps. Even when i dont get previous timestamps/pts I see frames with the clock before the previous frames that i received. However, when i turn off the Video Acceleration and I also wrote some code to get only the pts that come after the current pts I was able to play the camera stable with 5 seconds difference (I think that's a setting within the camera settings. I wasn't able to install the activex to check). Opening the same with potplayer had more delay. I was still getting a lot of errors from the camera
I need to see why with Video Acceleration previous frames are coming next, but I don't see any delay issue here. |
OK the problem with the Video Acceleration on and the wrong row of frames happens with both vlc and potplayer as well. I will attach and sample video for testing in the future maybe. Record1.mp4 |
You can play around with ffmpeg format context flags / options etc. I've managed to stream with 2 seconds difference (from my clock) with the following options:
I'm not sure what else to look with this one, so I will close this for now and probably I will try to expose those flags / options as well in config. |
Ok found it. Use UDP instead of TCP and use Video Acceleration as well! Works great with 1 second difference... Tested also with ffplay which has same behavior.
|
Further testing with my cameras proves that H265 (hevc) should be better choice and more stable for tcp with VA on.
|
Now realtime! 2021-07-26_22-43-17.mp4All modifications in Screamer():
|
I was able to play with low latency without commenting all those lines... is there any actual reason to comment them? |
May be with live stream as rtsp from ip camera, no need to compute and sleep Thread.Sleep (sleepMs) because you can't get the next frame if the frame has not been produced by the camera. Or, time to open video input too long => there is an error when calculate timestamp => wrong sleep time. |
The library must exposes as much as ffmpeg's low level configuration to the user. That doesn't mean that it will be able to configure by itself :( So, I'm afraid that anyone who uses the library needs to do some research on ffmpeg's options / flags etc. I will have a look if it's possible to expose also options for avformat_find_stream_info but it's important that the library will be able to open any input not just rtsp live cameras. I'm doing some research for network streams lately and I will have some enhancements soon. |
I've just added config.player.LowLatency which is focuses on cases like this one. Check it out and let me know. |
Now it works fine: 2021-07-30_22-45-53.mp4 |
Hi,
This issue has been reported before #18
After change some code in DemuxerBase.cs (attached file), it's better. Please review this change.
In this video you can see the video delay (of original code) when controlling the camera
framedelay2.mp4
DemuxerBase.zip
The text was updated successfully, but these errors were encountered: