Webcam stream macOs

Hi @meska, any update on what I should do? I appreciate the help.

Thanks

Hi @meska

First of all, thanks for what you have done.
I'm able to run your program and I get a stream from the iSight camera.

But I'm trying to setup your program in order to use a USB webcam instead of the iSight one.
I didn't find how to select the correct webcam.
Can you help me?

Hi,

I got it :slight_smile:

I read your code and I find the argument to use : "-c".
First I try value from 1 to 5 and that didn't work but I didn't connect the webcam :smiley:
When that was done (ie connect the cam), that's working fine with the value "1".

Have a good day

Hi @meska. I think I figured out my Python problem. It appears to be loading the virtual environment now, but I'm not getting the camera feed to load in the browser. Any idea what might be wrong?

Here's the output when running the startup commands:

iMac:Downloads rkz$ cd mjpeg_stream_webcam-master

iMac:mjpeg_stream_webcam-master rkz$ virtualenv -p python3.7 .env

Running virtualenv with interpreter /usr/local/bin/python3.7

Already using interpreter /usr/local/opt/python/bin/python3.7

Using base prefix '/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7'

New python executable in /Users/rkz/Downloads/mjpeg_stream_webcam-master/.env/bin/python3.7

Not overwriting existing python script /Users/rkz/Downloads/mjpeg_stream_webcam-master/.env/bin/python (you must use /Users/rkz/Downloads/mjpeg_stream_webcam-master/.env/bin/python3.7)

Installing setuptools, pip, wheel...

done.

iMac:mjpeg_stream_webcam-master rkz$ source .env/bin/activate

(.env) iMac:mjpeg_stream_webcam-master rkz$ pip install -r requirements.txt

Requirement already satisfied: opencvutils in ./.env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (0.9.4)

Requirement already satisfied: opencv-python in ./.env/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (4.2.0.34)

Requirement already satisfied: pillow in ./.env/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (7.1.1)

Requirement already satisfied: fake-rpi in ./.env/lib/python3.7/site-packages (from opencvutils->-r requirements.txt (line 1)) (0.7.0)

Requirement already satisfied: numpy in ./.env/lib/python3.7/site-packages (from opencvutils->-r requirements.txt (line 1)) (1.18.2)

Requirement already satisfied: pyyaml in ./.env/lib/python3.7/site-packages (from opencvutils->-r requirements.txt (line 1)) (5.3.1)

Requirement already satisfied: build-utils in ./.env/lib/python3.7/site-packages (from opencvutils->-r requirements.txt (line 1)) (0.3.2)

Requirement already satisfied: colorama in ./.env/lib/python3.7/site-packages (from build-utils->opencvutils->-r requirements.txt (line 1)) (0.4.3)

Requirement already satisfied: twine in ./.env/lib/python3.7/site-packages (from build-utils->opencvutils->-r requirements.txt (line 1)) (3.1.1)

Requirement already satisfied: nose in ./.env/lib/python3.7/site-packages (from build-utils->opencvutils->-r requirements.txt (line 1)) (1.3.7)

Requirement already satisfied: importlib-metadata; python_version < "3.8" in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (1.6.0)

Requirement already satisfied: readme-renderer>=21.0 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (25.0)

Requirement already satisfied: requests>=2.20 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (2.23.0)

Requirement already satisfied: requests-toolbelt!=0.9.0,>=0.8.0 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (0.9.1)

Requirement already satisfied: keyring>=15.1 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (21.2.0)

Requirement already satisfied: pkginfo>=1.4.2 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (1.5.0.1)

Requirement already satisfied: tqdm>=4.14 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (4.45.0)

Requirement already satisfied: setuptools>=0.7.0 in ./.env/lib/python3.7/site-packages (from twine->build-utils->opencvutils->-r requirements.txt (line 1)) (46.1.3)

Requirement already satisfied: zipp>=0.5 in ./.env/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (3.1.0)

Requirement already satisfied: Pygments>=2.5.1 in ./.env/lib/python3.7/site-packages (from readme-renderer>=21.0->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (2.6.1)

Requirement already satisfied: six in ./.env/lib/python3.7/site-packages (from readme-renderer>=21.0->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (1.14.0)

Requirement already satisfied: docutils>=0.13.1 in ./.env/lib/python3.7/site-packages (from readme-renderer>=21.0->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (0.16)

Requirement already satisfied: bleach>=2.1.0 in ./.env/lib/python3.7/site-packages (from readme-renderer>=21.0->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (3.1.4)

Requirement already satisfied: idna<3,>=2.5 in ./.env/lib/python3.7/site-packages (from requests>=2.20->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (2.9)

Requirement already satisfied: chardet<4,>=3.0.2 in ./.env/lib/python3.7/site-packages (from requests>=2.20->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (3.0.4)

Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./.env/lib/python3.7/site-packages (from requests>=2.20->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (1.25.9)

Requirement already satisfied: certifi>=2017.4.17 in ./.env/lib/python3.7/site-packages (from requests>=2.20->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (2020.4.5.1)

Requirement already satisfied: webencodings in ./.env/lib/python3.7/site-packages (from bleach>=2.1.0->readme-renderer>=21.0->twine->build-utils->opencvutils->-r requirements.txt (line 1)) (0.5.1)

(.env) iMac:mjpeg_stream_webcam-master rkz$ 

Super Super! been messing around with VLC and trying to get this to work on my Mac mini.

I have installed perfectly and it works out of the box. I can see the camera when on my Mac mini.

But... (you knew it was coming)
I cannot view the camera on any other machine on my network. Is there a config file I can edit to change the server address from localhost to the IP address of the machine (internal IP)?

Solved:
Edited mjpegsw.py
parser.add_argument('-i', '--ipaddress', help='listening ip address, default LOCALIP ADDRESS', type=str,
default='LOCALIPADDRESS')

On this point did you find a way to restart the octoprint server and enter a password (or bypass this?)

Meska,
First off, thanks for investing the time to figure out how to put all of pieces together and then writing the python script.

FYI... I am a veteran software engineer and have been using python for around 4 years now professionally.

I using a mid-2011 Mac-mini running macOS 10.13.6

for octoprint:

  • I made sure I had all the Xcode and Xcode cli tools installed
  • I downloaded & installed python 2.7.18 from python.org
  • then using pip from that installation, I installed virtualenv
  • created a new python virtual environment
  • I cloned the source code from the octoprint repository
  • activated the virtualenv
  • pip installed pyobjc
  • and finally did a pip install . from the root of the repo
  • I did discover to connect from the Mac-mini to my Creality CR-6 SE that I had to install the CH341SER_MAC very 1.5 drivers

After that, I can get octoprint up and running just fine, connect to it from remote computers, send print jobs to it, etc. Everything is stable.

Next for mjpeg_stream_webcam

  • I downloaded & installed python 3.8.5 from python.org
  • then using pip from that installation, I installed virtualenv
  • created a new python virtual environment
  • cloned your git hub repo

but when I tried to install the requirements from the included requirements.txt file, I got the error that there were no matching distributions found for opencvutil (line 1)

so I took a look at the mjpegsw.py script and did not see any imports (as far as I could tell) for this package. So I manually pip installed the other 2 remaining packages.

with the 3.8.5 virtualenv activated I was able to successfully execute python mjpegsw.py with the default arguments and then view the stream by going to http://localhost:5001/cam.mjpg in safari. So I knew that was working.

I did the configuration in octoprint to set the respective values for the stream and snapshot URLs.
Then realized that I needed to install ffmpeg. So I downloaded the static FFmpeg binaries for macOS 64-bit (version release-4.3.1). installed in to my ~/bin directory verified that it worked, and updated the path setting in octoprint.

So I could see the webcam stream in octoprint and could start a time-lapse capture when doing a print.

However, during the printing, I would occasionally get segmentation fault 11 errors, so I'd restart the program again. After a few of these, I got a kernel panic. So I shut down the computer and thought I'd try again tomorrow. I did and even without printing (just viewing the webcam stream), got another kernel panic.

Any ideas as to what might be causing the segmentation fault 11 errors? or worse the kernel panics? I can upload the kernel panic log files, if it will help. I haven't used CV before, but I have a rudimentary idea of what your doing in the script... and it doesn't look terrible complex. Do you think its something in CV or one of the dependencies that were installed along with it? I wouldn't think its the http.server package or the PIL package...

Any suggestions? I'm willing to help troubleshoot.

Best Regards,
-- Greg

Hello Greg,
segfaults sometimes happens, that's why I included a startup script "start.sh" that relaunch the script on crash. You can try with different ffmpeg or opencv versions to see if changes.
I removed opencvutils from requirements, thank you.

Meska,
Thanks for the reply. I get that the start.sh script is a workaround for the script expectedly quitting (due to whatever), but this wasn't, I don't know, as eloquent as I would have liked, as I suspect that the crashes may be contributing to the Kernel panics I am experiencing when I have the script running.

In any event, let me know if you think of any specific components that I should take a look at to narrow it down a bit.

Thanks again for all the great work, keep it up!

By the way... you should have said: "Segfaults happen"... it would have made a great bumper sticker!

Best Regards,
-- Greg