Motion-Project / motion

Motion, a software motion detector. Home page: https://motion-project.github.io/
GNU General Public License v2.0
3.64k stars 547 forks source link

[doc] Non-compliant RTSP camera workaround for "Invalid data found when processing input" #1071

Closed stokie-ant closed 3 years ago

stokie-ant commented 4 years ago

This is not a bug in motion and not a bug in ffmpeg. In fact ffmpeg is doing what it is supposed to do. It's more a bug in the camera.

ffmpeg sends the setup request with the header:

Transport: RTP/AVP/TCP;

But the camera replies with:

Transport: RTP/AVP;

ffmpeg sees no tcp, thinks the camera is trying to drop to udp and bails.

The previous workaround was to set netcam_use_tcp off to force udp but, as the manual says:

This option specifies the transport method for rtsp/rtmp cameras. The TCP transport is highly preferred because without this option the rtsp/rtmp images are frequently corrupted and result in many false positive values and images that appear to be smeared.

I don't know if some cameras are incapable of rtsp over tcp but a workaround I found to force use of tcp is to run a local instance of netsed and point the netcam_url at this instead Ex, instead of: netcam_url rtsp://192.168.0.51:554/onvif1

use: netcam_url rtsp://127.0.0.1:554/onvif1

Start netsed to substitude AVP; with AVP/TCP; netsed tcp 554 192.168.0.51 554 's/AVP;/AVP%2FTCP;'

Maybe the docs can refer to this workaround

tosiara commented 4 years ago

Interesting. Are you sure that netsed does not perform conversion UDP->TCP?

stokie-ant commented 4 years ago

I don't think netsed works like that. Besides, the image is now glitch free. If the connection between netsed and the camera was still udp the glitching would still be there

tosiara commented 4 years ago

Can you provide two motion logs with d -7 and two corresponding wireshark dumps: one for not working case and one that works with netsed?

stokie-ant commented 4 years ago

I have filtered the pcket captures to the camera with the issue (camera4, Allan Room). Notice that both network captures, packet 12 is the same except that with netsed the exchange succeeds. This is because the substitution is done on the local interface. I have included a capture of the local interface. Look at packet 12, you'll see the substitution of AVP; with AVP/TCP;

direct-no-netsed.pcapng.gz direct-no-netsed.motion.log using-netsed.pcapng.gz using-netsed.motion.log local-between-motion-netsed.pcapng.gz

tosiara commented 4 years ago

Yes, now that looks like a workaround. While ffmpeg tries to follow the protocol, there is currently no way to force TCP if the camera explicitly does not return TCP in DESCRIBE. We could add the workaround into the documentation Thanks!

analogue commented 4 years ago

+1 Been trying to figure out why my cam doesn't work and this explains it all too well. Please document the workaround somewhere in the motion docs.

@stokie-ant TIL netsed!

stokie-ant commented 4 years ago

+1 Been trying to figure out why my cam doesn't work and this explains it all too well. Please document the workaround somewhere in the motion docs.

@stokie-ant TIL netsed!

Glad to help. Just out of interest, what make/model do you have? Mine is a Sricam sp012. I think it might be a good idea to compile a list somewhere of non compliant devices this does or does not work for

analogue commented 4 years ago

+1 Been trying to figure out why my cam doesn't work and this explains it all too well. Please document the workaround somewhere in the motion docs. @stokie-ant TIL netsed!

Glad to help. Just out of interest, what make/model do you have? Mine is a Sricam sp012. I think it might be a good idea to compile a list somewhere of non compliant devices this does or does not work for

I'm working with a YooSee SD-M5 Doorbell camera which seems to be based on:

Mr-Dave commented 3 years ago

closed via #1275

eusoubrasileiro commented 3 years ago

I am sharing how I solved this exact issue for my Yoosee IP camera. I hope it will help someone else. Sorry for the long answer but that's to make as clear as possible to everybody. https://stackoverflow.com/q/66280861/1207193 In summary: I modified the ffmpeg/libavformat/rtsp.c source code and rebuilt custom FFMPEG libraries that works for my Yoosee camera. Not breaking any functionality. Since in my case I can't (or don't want to) use another process over it like with the netsed solution.