Skip to content
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

Approximately 6 second delay on RTSP stream #37

Closed
withtypes opened this issue Nov 29, 2017 · 21 comments
Closed

Approximately 6 second delay on RTSP stream #37

withtypes opened this issue Nov 29, 2017 · 21 comments

Comments

@withtypes
Copy link

Hi,

I tried to use StreamPlayerControl and it works fine except there is a 6 second delay in the stream. I've looked into StreamPlayer C++ code but couldn't find anything there that might cause this. I also couldn't build StreamPlayer C++ code, do you maybe have instructions for it? I would like to debug it somehow...

By the way, I'm using a cheap camera but I also tried it in ONVIF Device Manager https://sourceforge.net/projects/onvifdm/ and there live stream worked flawlessly (no delays, perfect image).

Do you have any ideas what might cause this?

@jacobbo
Copy link
Owner

jacobbo commented Nov 29, 2017

Hi,

Is if 6 seconds in the beginning of the stream, i.e. the first frame appears 6 seconds later after you press the Play button?

@jacobbo
Copy link
Owner

jacobbo commented Nov 29, 2017

To build the C++ part of the control you will need to build FFmpeg and boost first. The instructions are here: #33 (comment)

@withtypes
Copy link
Author

withtypes commented Nov 29, 2017 via email

@jacobbo
Copy link
Owner

jacobbo commented Nov 29, 2017

@frankpc3
Copy link

frankpc3 commented Nov 30, 2017

There is no delay on the StreamPlayer. I run my cameras into Blue Iris and I use the StreamPlayer control to play the video from BI on the desktop. Within a quarter of a second from the time motion is detected, the video begins to play. However, I first used StreamPlayer to play the video directly from the camera. When you try that, the video does not fully display until the I frame shows up. That just doesn't work. But the problem isn't with StreamPlayer control, it is with the process of starting the camera and trying to sync the video. And I doubt it would make a difference as to which camera you use. Not sure about that. But I did have the same problem with 5 different brands of cameras.

@withtypes
Copy link
Author

withtypes commented Nov 30, 2017

@jacobbo in theory, could I force the frame queue (ConcurrentQueue queue_) to skip "stale" frames e.g. after pop I empty it (or leave one frame at most) and only after that I take sleep_for(interframeDelay)?

This way I might skip some frames but it would always show the latest frame? What do you think? I will try to recompile StreamPlayer and replace .dll

@jacobbo
Copy link
Owner

jacobbo commented Nov 30, 2017

Your idea is that for the first 6 seconds the stream has 'stale' frames, isn't? But then it's not a control's issue, that's a stream's issue.

Regarding your question, yes, you can skip frames, but this will be a very custom solution and you need a criteria based on which you will be skipping frames.

@withtypes
Copy link
Author

Sorry to bother you but I would like to try out that solution but I cannot get ffmpeg to compile. I've followed the instructions you provided as well as their guide https://trac.ffmpeg.org/wiki/CompilationGuide/MSVC

$ make CC libavformat/mxfenc.o mxfenc.c libavformat/mxfenc.c(1447): error C2059: syntax error: '}' make: *** [libavformat/mxfenc.o] Error 2

Which seems like c99 syntax problem. But they mentioned this is something to worry about only on <2012 MSVC

Do you have any advice maybe how to simplify the build procedure? I tried to find pre-compiled binaries of boost/ffmpeg and try with them.

@jacobbo
Copy link
Owner

jacobbo commented Nov 30, 2017

I do not remember such an issue. Which tools are you using to build it? I successfully build it using MSVC 2015 + MSYS + YASM x64.

Pre-compiled binaries will not work, as I use static linking for FFmpeg.

@withtypes
Copy link
Author

I fixed the compilation issue and managed to compile ffmpeg with ./configure --toolchain=msvc --arch=amd64 --target-os=win64 --enable-version3 --enable-static --disable-shared --disable-programs --disable-doc and make

I've added everything into VC++ Directories (Library/Include) for Release x64. Still I cannot get it to compile, it says Severity Code Description Project File Line Suppression State Error LNK1104 cannot open file 'libpostproc.a' StreamPlayer C:\Users\Hrvoje\work\WebEye\StreamPlayerControl\StreamPlayer\StreamPlayer\LINK .

I cannot find .a files anywhere. I would expect them after compiling ffmpeg with the static option :(

@jacobbo
Copy link
Owner

jacobbo commented Dec 2, 2017

That's correct, the .a files should be generated by make.

@jacobbo
Copy link
Owner

jacobbo commented Dec 2, 2017

btw, have you tried ffplay?

@withtypes
Copy link
Author

I did, there is a lag also (2 seconds).

Tail:
[h264 @ 000000000289b720] concealing 1245 DC, 1245 AC, 1245 MV errors in I frame
[rtsp @ 00000000027e8b20] max delay reached. need to consume packet
[rtsp @ 00000000027e8b20] RTP: missed 34 packets
[h264 @ 00000000038835e0] negative number of zero coeffs at 18 45
[h264 @ 00000000038835e0] error while decoding MB 18 45
[h264 @ 00000000038835e0] concealing 2791 DC, 2791 AC, 2791 MV errors in I frame
[rtsp @ 00000000027e8b20] max delay reached. need to consume packet
[rtsp @ 00000000027e8b20] RTP: missed 25 packets
[h264 @ 0000000003883d60] corrupted macroblock 51 54 (total_coeff=-1)
[h264 @ 0000000003883d60] error while decoding MB 51 54 0B f=1/1
[h264 @ 0000000003883d60] concealing 1678 DC, 1678 AC, 1678 MV errors in I frame
[rtsp @ 00000000027e8b20] max delay reached. need to consume packet
[rtsp @ 00000000027e8b20] RTP: missed 36 packets
[h264 @ 0000000003a20380] corrupted macroblock 8 43 (total_coeff=-1)
[h264 @ 0000000003a20380] error while decoding MB 8 43
[h264 @ 0000000003a20380] concealing 3041 DC, 3041 AC, 3041 MV errors in I frame
[rtsp @ 00000000027e8b20] max delay reached. need to consume packet
[rtsp @ 00000000027e8b20] RTP: missed 30 packets
[h264 @ 0000000003ce56a0] negative number of zero coeffs at 38 47
[h264 @ 0000000003ce56a0] error while decoding MB 38 47
[h264 @ 0000000003ce56a0] concealing 2531 DC, 2531 AC, 2531 MV errors in I frame
35.56 M-V: -0.112 fd= 7 aq= 0KB vq= 0KB sq= 0B f=1/1

@withtypes
Copy link
Author

Running ffplay -rtsp_transport tcp -probesize 32 makes it better.

@jacobbo
Copy link
Owner

jacobbo commented Dec 2, 2017

I see. The control supports setting the rtsp_transport option, but doesn't support the probesize option.
You could try to create a custom build with hardcoded probesize setting. I think, you just need to add it to the dictionary in the Stream::GetOptions() method

av_dict_set(&optionsPtr, "rtsp_transport", "tcp", 0);

@withtypes
Copy link
Author

But I don't understand ffmpeg, I did configure ..., make, make install shouldn't .a files be in the same directory (under respective subdirs)?

@jacobbo
Copy link
Owner

jacobbo commented Dec 2, 2017

'make install' is not needed, just 'make' is enough in my case. Also, make produces logging info, you could forward it to a file and find out what's going on.

@withtypes
Copy link
Author

Ah libpostproc was the problem. It's GPL so I had to add --enable-gpl to configure! You can update it in that procedure if you want...

Let't me try probe now!

@withtypes
Copy link
Author

Probe helped a little bit but in the end I removed that sleep and now it works <1s lag!

@jacobbo
Copy link
Owner

jacobbo commented Dec 2, 2017

You mentioned that some other players handle your stream correctly, i.e. without the lag.
I'm wondering what are they? Software that comes with camera?

@withtypes
Copy link
Author

withtypes commented Dec 2, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants