kroo / wyzecam

Python package for streaming video from wyze cameras over the local network
https://kroo.github.io/wyzecam/
MIT License
178 stars 15 forks source link

Detailed Linux (Debian) install notes #52

Open noelhibbard opened 3 years ago

noelhibbard commented 3 years ago

Okay, not really a question, just leaving some notes for really green Linux users.

# clone repo
git clone https://github.com/kroo/wyzecam.git && cd wyzecam

# Install python, pip and virtual environment
sudo apt-get install python3 python3-pip python3-venv -y

# create venv
python3 -m venv wyzetest
source wyzetest/bin/activate

# Install dependencies
pip install .
pip install requests
pip install opencv-python
pip install av

# Download, compile and install TUTK_IOTC
wget https://github.com/nblavoie/wyzecam-api/raw/master/wyzecam-sdk/TUTK_IOTC_Platform_14W42P1.zip
unzip TUTK_IOTC_Platform_14W42P1.zip
cd Lib/Linux/x64/
g++ -fpic -shared -Wl,--whole-archive libAVAPIs.a libIOTCAPIs.a -Wl,--no-whole-archive -o libIOTCAPIs_ALL.so
sudo cp libIOTCAPIs_ALL.so /usr/local/lib/
cd ../../..

# Set Wyze creds
export WYZE_EMAIL=johnd@example.com
export WYZE_PASSWORD=mypassword

# Set your camera name on line 20 of example:
nano examples/streaming_video.py

# run example
python examples/streaming_video.py
calvinnelms commented 3 years ago

I walked through the above steps, If I run the last command "python examples/streaming_video.py" I receive the following error:

Traceback (most recent call last):
  File "examples/streaming_video.py", line 7, in <module>
    from wyzecam import get_camera_list, get_user_info, login
ModuleNotFoundError: No module named 'wyzecam'

I am not too familiar with Python, how can I check that the wyzecam module exists?

mrlt8 commented 3 years ago

If you followed all the steps (including the .s), you should have the wyzecam module installed in the local venv which you can activate using the command source wyzetest/bin/activate.

If that still doesn't work you can try reinstalling it from the repo using pip install . (with the dot) or pip install wyzecam

rickgitdone commented 3 years ago

on Ubuntu I had to make another slight edit to ensure the venv was using python3.8 which does work... all pip & python calls must be pip3.8 & python3.8

clone repo

git clone https://github.com/kroo/wyzecam.git && cd wyzecam

Install python, pip and virtual environment

sudo apt-get install python3.8 python3.8-pip python3.8-venv -y

create venv

python3.8 -m venv wyzetest source wyzetest/bin/activate

Install dependencies

pip3.8 install . pip3.8 install requests pip3.8 install opencv-python pip3.8 install av

...

run example ( with venv activated )

python3.8 examples/streaming_video.py

Hope this helps ...

noelhibbard commented 3 years ago

@ricksdunn FYI, 'python' and 'pip' are linked to what ever version of python was used to create the venv.

So while in the venv, this:

python3.8 examples/streaming_video.py

Is the same as doing this:

python examples/streaming_video.py
calvinnelms commented 3 years ago

@ricksdunn , thanks, I am running ubuntu 20.04; running with python3.8 did the trick.

SomebodySysop commented 3 years ago

On latest Ubuntu 20.04.2.0 LTS.

wyzetest) ron@ToshibaWin7-Ubuntu:~$ pip3 --version pip 20.0.2 from /home/ron/wyzetest/lib/python3.8/site-packages/pip (python 3.8)

(wyzetest) ron@ToshibaWin7-Ubuntu:~$ python --version Python 3.8.5

Got this far in above instructions...

clone repo

git clone https://github.com/kroo/wyzecam.git && cd wyzecam

Install python, pip and virtual environment

sudo apt-get install python3 python3-pip python3-venv -y

create venv

python3 -m venv wyzetest source wyzetest/bin/activate

Install dependencies

pip install .

Then get this error:

(wyzetest) ron@ToshibaWin7-Ubuntu:~$ pip install . ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.

Don't know if I am on the correct directory. Just ran these from my /home directory. What should I do next?

Note:

I tried to get slick and copy the setup.py file to the directory in which I was working.

(wyzetest) ron@ToshibaWin7-Ubuntu:~$ cp /usr/share/hplip/setup.py . (wyzetest) ron@ToshibaWin7-Ubuntu:~$ pip3.8 install . Processing /home/ron ERROR: Command errored out with exit status 1: command: /home/ron/wyzetest/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-7lwko7hx/setup.py'"'"'; file='"'"'/tmp/pip-req-build-7lwko7hx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-7lwko7hx/pip-egg-info cwd: /tmp/pip-req-build-7lwko7hx/ Complete output (5 lines): Traceback (most recent call last): File "", line 1, in File "/tmp/pip-req-build-7lwko7hx/setup.py", line 47, in from base.g import * ModuleNotFoundError: No module named 'base'

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

SomebodySysop commented 3 years ago

sudo apt-get install python3.8 python3.8-pip python3.8-venv -y

I'm on latest Ubuntu. When I try this, I get the following error:

(wyzetest) ron@ToshibaWin7-Ubuntu:~/wyzecam/wyzecam$ sudo apt-get install python3.8 python3.8-pip python3.8-venv -y Reading package lists... Done Building dependency tree
Reading state information... Done E: Unable to locate package python3.8-pip E: Couldn't find any package by glob 'python3.8-pip' E: Couldn't find any package by regex 'python3.8-pip'

SomebodySysop commented 3 years ago

Got past the errors. Going to try the example.

SomebodySysop commented 3 years ago

Got past the pip install error by making sure I used python3.8.

Now attempting example. Prepared to edit examples/streaming_video.py and totally stumped by this:

cam = [camera for camera in cameras if camera.nickname == "Back Yard Cam"][
    0
]

What????

My camera name is simply WyzeCam301. Do I just replace the "0" with the camera name? And what happens when I add another camera? Sorry to be a bother, but this is a bit unclear.

mrlt8 commented 3 years ago

Replace "Back Yard Cam" with the camera nickname you set in the wyze app.

Or if you simply want to get the first cam, just use:

cam = cameras[0]
SomebodySysop commented 3 years ago

Replace "Back Yard Cam" with the camera nickname you set in the wyze app.

Or if you simply want to get the first cam, just use:

cam = cameras[0]

Got it! Thank you!

I got a connection, but then python crashed!

(wyzetest) ron@ToshibaWin7-Ubuntu:~/wyzecam/wyzecam$ python3.8 examples/streaming_video.py 6, session_info = SInfoStruct: mode: 2 uid: b'45FX8Z1XY4M55RAP111A' remote_ip: b'192.168.1.211' remote_port: 191 tx_packet_count: 14 got av frame 23936 codec: 78 ts: 1624594040.507448 keyframe: 0 frame rate: 20 frame size: 0 bitrate: 120 qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ron/wyzecam/wyzecam/wyzetest/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)

SomebodySysop commented 3 years ago

OK, sorry everybody! I was ssh'd into my Ubuntu machine (I'm real old school). When I executed command from the machine terminal itself, boom, there I was in living color! Example works! Whoo-Hoo!

On to next leg of the journey!

hobbez commented 3 years ago

Went through all the steps fine on both Ubuntu and MacOS, however am getting "validation errors for WyzeCredential access_token". I have verified credentials are correct in env vars. Also tried hard cording creds in streaming_video.py and got the same error. Any suggestions on what else to check?

$ python examples/streaming_video.py 
Traceback (most recent call last):
  File "examples/streaming_video.py", line 51, in <module>
    main()
  File "examples/streaming_video.py", line 16, in main
    auth_info = login(os.environ["WYZE_EMAIL"], os.environ["WYZE_PASSWORD"])
  File "/usr/local/src/wyze/wyzecam/wyzetest/lib/python3.8/site-packages/wyzecam/api.py", line 49, in login
    return WyzeCredential.parse_obj(dict(resp.json(), phone_id=phone_id))
  File "pydantic/main.py", line 578, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 3 validation errors for WyzeCredential
access_token
  none is not an allowed value (type=type_error.none.not_allowed)
refresh_token
  none is not an allowed value (type=type_error.none.not_allowed)
mfa_options
  value is not a valid dict (type=type_error.dict)
versamodule commented 3 years ago

@noelhibbard, Thank you so much for your post. Being green, there was no way i could have pulled this off with the basic instructions that were given. It worked for me with no issues. I would have been nice if they made a way for VLC to connect to it. VcXsrv Windows X Server, goes full screen which is kinda useless without being able to resize it.

kroo commented 3 years ago

@hobbez it looks like you likely have 2fa set up. See https://github.com/kroo/wyzecam/issues/57

hobbez commented 3 years ago

@kroo - confirmed, thanks!

mrlt8 commented 3 years ago

I would have been nice if they made a way for VLC to connect to it. VcXsrv Windows X Server, goes full screen which is kinda useless without being able to resize it.

Why don't you just pipe it directly to VLC?

with wyzecam.WyzeIOTC() as wyze_iotc:
  with wyze_iotc.connect_and_auth(account, camera) as sess:
    for (frame,_) in sess.recv_video_data():
      sys.stdout.buffer.write(frame)

python myscript.py | VLC - --demux h264

versamodule commented 3 years ago

I would have been nice if they made a way for VLC to connect to it. VcXsrv Windows X Server, goes full screen which is kinda useless without being able to resize it.

Why don't you just pipe it directly to VLC?

with wyzecam.WyzeIOTC() as wyze_iotc:
  with wyze_iotc.connect_and_auth(account, camera) as sess:
    for (frame,_) in sess.recv_video_data():
      sys.stdout.buffer.write(frame)

python myscript.py | VLC - --demux h264

Because I know to little about Linux,, and know even less about Python. But I can copy and paste ;-) Thank you for the info though. I need to research more, as my goal now is to have a RPI board do this, and then (if possible) act as a streaming server so that on my PC I can use VLC to connect to the RPI board to receive the video feed.

rickgitdone commented 3 years ago

did you try this pipe idea? Does it work?

I ended up using the fiveleaves hack and use cvlc ( command line binary ) of vlc and take the hack output and restream to rtsp locally

cvlc -vvv http://[cam IP]:12345 --sout '#rtp{sdp=rtsp://:8554/}' --demux h264 &

... my NVR then slurps up rtsp feed

... I will try this idea soon...

rickgitdone commented 3 years ago

I would have been nice if they made a way for VLC to connect to it. VcXsrv Windows X Server, goes full screen which is kinda useless without being able to resize it.

Why don't you just pipe it directly to VLC?

with wyzecam.WyzeIOTC() as wyze_iotc:
  with wyze_iotc.connect_and_auth(account, camera) as sess:
    for (frame,_) in sess.recv_video_data():
      sys.stdout.buffer.write(frame)

python myscript.py | VLC - --demux h264

Because I know to little about Linux,, and know even less about Python. But I can copy and paste ;-) Thank you for the info though. I need to research more, as my goal now is to have a RPI board do this, and then (if possible) act as a streaming server so that on my PC I can use VLC to connect to the RPI board to receive the video feed.

for (frame,_) in sess.recv_video_data():
      sys.stdout.buffer.write(frame)   

the conversion to stdout in terminal isn't working out to be able to use VLC to restream

I tried several adjustments in VLC and also piped to a file but the output was no good.. I am thinking the output needs to stay binary to be able to use it and sys.stdout.buffer.write(frame) examples do sys.stdout.buffer.write(b"frame") and that doesn't work either... I will also try the ffmpeg example to see if that can be piped into vlc to restream to rtsp w/o need for TinyCam or NgnX stuff