mrlt8 / docker-wyze-bridge

WebRTC/RTSP/RTMP/LL-HLS bridge for Wyze cams in a docker container
GNU Affero General Public License v3.0
2.63k stars 161 forks source link

Streams flipped with latest update #976

Open frakman1 opened 1 year ago

frakman1 commented 1 year ago

I've been using this container without issues for a long time. Last time I updated was a week or so ago. Not sure what version. However, today I just updated it to v2.3.16 and all the streams are upside down. Did something change to make that happen?

I looked and I see a rotate option (ROTATE_CAM_xxx) in the environment variables that I can set but I never used to use that before so not sure why it's now required.

The cameras are in normal orientation and not upside down or anything.

Another observation is that it occasionally flips back to normal every now and then. It only seems to happen with the cameras with the official RTSP FW on them. Could that be it?

mrlt8 commented 1 year ago

hmm, is the video flipped in the app as well? The rotate option is not required and only there for people who want to do 90ΒΊ rotations since the cameras can only do vertical flip or horizontal rotation. You should be able to see if your camera has the flip enabled in the web-ui or via the API: http://<bridge ip>:5000/api/<cam-name>/caminfo it should be under videoParm

frakman1 commented 1 year ago

Thank you for the insight and tips. I checked and all the cameras (v2 classic) with the RTSP firmware on them have this setting under videoParm:

{ "bitRate": "30", "fps": "15", "horizontalFlip": "1", "logo": "2", "resolution": "2", "time": "2", "verticalFlip": "5" }

They are also flipped in the app. They keep flip flopping randomly or when I make changes or restart the cameras in the app or when I restart the docker. I even tried to set the Rotate 180 button on them with no luck. I get inconsistent behavior.

The stock camera (Pan v1) (not flipped) has:

{ "bitRate": "30", "fps": "15", "horizontalFlip": "1", "logo": "2", "resolution": "2", "time": "2", "type": "H264", "verticalFlip": "1" }

What is causing the verticalFlip parameter to be set to 5? Can it be locked to 1 or whatever makes it not flipped?

frakman1 commented 1 year ago

I'm really confused now. I checked today and although the streams are in the correct orientation on the Web-UI, they all still show as "verticalFlip": "5"

frakman1 commented 1 year ago

Further observation. Whether the stream is flipped or not in the WebUI, the value for verticalFlip is always 5

mrlt8 commented 1 year ago

The bridge doesn't send any commands related to vertical or horizontal flip, so not sure where the issue is coming from.

IIRC, videoParam only gets returned on the initial connection, so it might not update until a reconnect.

You may be able to query the info from camera_info or param_info #825 using:

http://<bridge ip>:5000/api/<cam-name>/camera_info
http://<bridge ip>:5000/api/<cam-name>/param_info/6,7

Will try to add flip related controls in the next version.

frakman1 commented 1 year ago

Agreed that it may not be related to this docker bridge or the upgrade specifically but it's strange that it only happens when using the stream I get from the docker bridge. It didn't happen when I accessed the RTSP stream directly from the camera.

I checked my camera monitoring software (Contacam) and can confirm that all the v2 cameras with the RTSP FW flipped at the same time overnight at 4:42AM:

rec_2023_08_29_04_42_25 rec_2023_08_29_04_42_24 rec_2023_08_29_04_42_33

The Pan v1 camera with the stock Wyze FW did not flip.

mrlt8 commented 1 year ago

That just makes things even stranger... do they eventually flip back on their own? Can you try manually flipping them in the app to see if you can get the verticalFlip value to 1?

Can you also see if there's anything in the logs around the time of the flip?

frakman1 commented 1 year ago

do they eventually flip back on their own?

All but one camera reverted to the correct orientation (eventually)

I have resorted to flipping the image in the camera monitoring software as a workaround but have to keep doing/undoing that as the streams keep flip flopping haha

More information: My WiFi router auto reboots at 7AM in the morning. The camera that remained flipped would not reconnect until much later after 9AM despite all other cameras working.

Using the API endpoints you provided

Upside down camera: (not sure what this output means)

{"command":"camera_info","payload":"","response":{"1":"2","10":"1","11":"2","12":"2","13":"1","14":"5","15":"0","16":"5","17":"1","18":"1","19":"60","2":"3","20":"1440","21":"2","22":"-5","23":"102","24":"58","25":"0","26":"1","27":"2","28":"2","29":"25","3":"30","30":"25","31":"50","32":"50","33":"2","34":"0","35":"0","36":"0","37":"0","38":"0","39":"0","4":"1","40":"0","41":"0","42":"0","43":"0","44":"0","45":"2","46":"30","47":"2","48":"50","49":"1","5":"15","50":"2","51":"0","52":"0","53":"0","54":"0","55":"0","56":"0","57":"0","58":"0","59":"0","6":"1","60":"0","7":"5","8":"2","9":"1"},"status":"success","value":{"1":"2","10":"1","11":"2","12":"2","13":"1","14":"5","15":"0","16":"5","17":"1","18":"1","19":"60","2":"3","20":"1440","21":"2","22":"-5","23":"102","24":"58","25":"0","26":"1","27":"2","28":"2","29":"25","3":"30","30":"25","31":"50","32":"50","33":"2","34":"0","35":"0","36":"0","37":"0","38":"0","39":"0","4":"1","40":"0","41":"0","42":"0","43":"0","44":"0","45":"2","46":"30","47":"2","48":"50","49":"1","5":"15","50":"2","51":"0","52":"0","53":"0","54":"0","55":"0","56":"0","57":"0","58":"0","59":"0","6":"1","60":"0","7":"5","8":"2","9":"1"}}

{"command":"param_info","payload":"6,7","response":{"6":"1","7":"5"},"status":"success","value":{"6":"1","7":"5"}}

Correct Camera:

{"command":"camera_info","payload":"","response":{"1":"2","10":"1","11":"2","12":"2","13":"1","14":"5","15":"1","16":"5","17":"1","18":"1","19":"0","2":"3","20":"1440","21":"2","22":"-4","23":"61","24":"102","25":"0","26":"1","27":"2","28":"2","29":"21","3":"30","30":"0","31":"61","32":"98","33":"2","34":"0","35":"0","36":"0","37":"0","38":"0","39":"0","4":"2","40":"0","41":"0","42":"0","43":"0","44":"0","45":"2","46":"30","47":"2","48":"50","49":"1","5":"15","50":"1","51":"1","52":"0","53":"0","54":"0","55":"0","56":"0","57":"0","58":"0","59":"0","6":"1","60":"0","7":"5","8":"2","9":"1"},"status":"success","value":{"1":"2","10":"1","11":"2","12":"2","13":"1","14":"5","15":"1","16":"5","17":"1","18":"1","19":"0","2":"3","20":"1440","21":"2","22":"-4","23":"61","24":"102","25":"0","26":"1","27":"2","28":"2","29":"21","3":"30","30":"0","31":"61","32":"98","33":"2","34":"0","35":"0","36":"0","37":"0","38":"0","39":"0","4":"2","40":"0","41":"0","42":"0","43":"0","44":"0","45":"2","46":"30","47":"2","48":"50","49":"1","5":"15","50":"1","51":"1","52":"0","53":"0","54":"0","55":"0","56":"0","57":"0","58":"0","59":"0","6":"1","60":"0","7":"5","8":"2","9":"1"}}

{"command":"param_info","payload":"6,7","response":{"6":"1","7":"5"},"status":"success","value":{"6":"1","7":"5"}}

frakman1 commented 1 year ago

Can you also see if there's anything in the logs around the time of the flip?

I checked the logs using docker logs docker-wyze-bridge and the Unraid logs menu. Unfortunately, they are not timestamped so I can not isolate anything. e.g.

[WyzeBridge] πŸŽ‰ Connecting to WyzeCam Pan - Living Room Cam on xxx
[living-room-cam] [-3] IOTC_ER_ALREADY_INITIALIZED
[WyzeBridge] ☁️ Pulling "living-room-cam" thumbnail to /img/living-room-cam.jpg
[WyzeBridge] xxx - - [27/Aug/2023 18:13:34] "GET /img/living-room-cam.jpg HTTP/1.1" 200 -
[WyzeBridge] xxx - - [27/Aug/2023 18:13:34] "GET /img/living-room-cam.jpg HTTP/1.1" 304 -
[WyzeBridge] Adding /basement-ac-gate-fw as a source
[WyzeBridge] starting MediaMTX 1.0.0
[WyzeBridge] 🎬 5 streams enabled
[WyzeBridge] πŸŽ‰ Connecting to WyzeCam V2 - Basement AC2 on XXX
[WyzeBridge] πŸŽ‰ Connecting to WyzeCam V2 - Garage Cam on XXX
[WyzeBridge] XXX - - [27/Aug/2023 18:13:49] "GET /img/living-room-cam.jpg HTTP/1.1" 304 -
[WyzeBridge] XXX - - [27/Aug/2023 18:13:49] "GET /img/living-room-cam.jpg HTTP/1.1" 304 -
[WyzeBridge] πŸŽ‰ Connecting to WyzeCam V2 - Basement AC gate on 192.168.86.111
[basement-ac2] πŸ“‘ Getting 30kb/s SD stream (h264/15fps) via LAN mode (WiFi: 89%) FW: 4.28.4.41 (2/3)
[garage-cam] πŸ“‘ Getting 30kb/s SD stream (h264/15fps) via LAN mode (WiFi: 92%) FW: 4.28.4.41 (2/3)
[basement-ac2] πŸ”Š Audio Enabled - PCM > AAC/8,000Hz
[basement-ac2] WARNING: Skipping smaller frame at start of stream (frame_size=0)
[garage-cam] πŸ”Š Audio Enabled - PCM > AAC/8,000Hz
[basement-ac-gate] πŸ“‘ Getting 30kb/s SD stream (h264/15fps) via LAN mode (WiFi: 96%) FW: 4.28.4.41 (2/3)
[basement-ac-gate] πŸ”Š Audio Enabled - PCM > AAC/8,000Hz
[garage-cam] WARNING: Waiting for keyframe
[basement-ac2] WARNING: Waiting for keyframe
[basement-ac-gate] WARNING: Waiting for keyframe
[WyzeBridge] βœ… '/garage-cam stream is UP! (3/3)
[WyzeBridge] πŸ“– New client reading from garage-cam
[WyzeBridge] βœ… '/basement-ac2 stream is UP! (3/3)
[WyzeBridge] πŸ“– New client reading from basement-ac2
[WyzeBridge] βœ… '/basement-ac-gate stream is UP! (3/3)
[WyzeBridge] πŸ“– New client reading from basement-ac-gate

Is there some other log file I could check?

frakman1 commented 1 year ago

Can you try manually flipping them in the app to see if you can get the verticalFlip value to 1?

Before: http://:5001/api/basement-ac-gate/param_info/6,7 {"command":"param_info","payload":"6,7","response":{"6":"1","7":"5"},"status":"success","value":{"6":"1","7":"5"}}

After checking the 'Rotate Image 180' button in the App: {"command":"param_info","payload":"6,7","response":{"6":"2","7":"5"},"status":"success","value":{"6":"2","7":"5"}}

It's still flipped after using the 'Rotate Image 180' button but it seems it's a horizontal flip. image

image

After toggling that button a few times, I noticed it eventually returns to normal (briefly): {"command":"param_info","payload":"6,7","response":{"6":"1","7":"1"},"status":"success","value":{"6":"1","7":"1"}}

But then, reverts to being flipped again. I observed my camera software during this test and I think it's because the camera software attempts to re-connect and maybe causes the flip? Or maybe the bridge's interaction with the camera caused it. I don't really know.

Another observation:

For some reason, the problematic feed, wouldn't show up in the bridge's webUI (black screen and wouldn't play) even though the URL was delivering a stream to the camera software. So I restarted the bridge, and then all of the RTSP FW feeds flipped! I reset one of the flipped cameras in the app, and it came up in the correct orientation in the app for a while, then eventually flipped too. Even the RTSP stream URL from the WebUI was flipped, however the RTSP snapshot was not (!?) (I'm so confused)

frakman1 commented 1 year ago

Something I've tried: Enable the proxy stream via this setting: image

I did see the new FW_RTSP stream but noticed two things:

1- URL has the fw suffix instead of the -fw suffix: image

2- The URL doesn't work in VLC (I tried both the fw and -fw suffix. Even though the regular non fw suffix works. image

frakman1 commented 1 year ago

No sure why or what happens at this time, but at exactly 4:42 AM, the cameras flipped again today

UPDATE: I looked into it and apparently, about a year ago, due to stability issues, I had to auto-restart the docker-wyze-bridge container within Unraid every day to get a consistent camera feed. Apparently Unraid decided that "Scheduled Daily" means at 4:40AM every day ! haha

image
docker-wyze-bridge
Script Finished Aug 30, 2023  04:40.47

So at least the timing mystery is solved, but still don't understand why it causes a flip.

frakman1 commented 1 year ago

Question. Have you ever used docker-wyze-bridge with the Wyze v2 cams running RTSP Firmware? Not sure if camera model is important or not but it seems to work fine with stock FW but not with the RTSP Firmware.

mrlt8 commented 1 year ago

I have one cam on RTSP for testing, but have never had anything like this happen.

frakman1 commented 1 year ago

Ahh good. Perhaps you can setup a listener to that camera via the docker-wyze-bridge stream URL (not the camera's native RTSP URL) and when everything is working, restart the bridge and see if it flips for you.

frakman1 commented 1 year ago

~~Was the above commit meant to be a fix? I just updated to the latest v2.3.17 but didn't see an option to flip under Controls. If it's a REST API change, can you provide some instructions please? I didn't see an update in the documentation about ver_flip or hor_flip. An example curl command would be ideal as I'm not sure what the POST parameters should look like.~~

Update: I now see that I can make a 'set' operation without using POST. The REST API documentation initially confused me because it says It says GET instead of SET under 'SET Value' (now I understand that that's an HTTP GET, not an actual parameter GET):

image

Anyway, I stumbled upon this documentation which made it clear:

image

I was able to 'un-flip' the camera feed by using this:

http://<bridge-ip>:<port>/api/garage-cam/ver_flip/1

I then made a cron job to do the same every hour:

cam1=http://<bridge-ip>:<port>/api/mycam1/ver_flip/1
cam2=http://<bridge-ip>:<port>api/mycam2/ver_flip/1
cam3=http://<bridge-ip>:<port>/api/mycam3/ver_flip/1
cam4=http://<bridge-ip>:<port>/api/mycam4/ver_flip/1

curl -v --parallel --parallel-immediate --parallel-max 4 ${cam1} ${cam2} ${cam3} ${cam4} 
frakman1 commented 1 year ago

Request: It would be nice if the WebUI had a button under 'Controls' that allowed you to flip the camera.