Using the package mjpg-streamer
curl -sL https://bit.ly/2A43ZHu | bash -
After installation, close your terminal and restart.
Look at https://github.com/OctoPrint/OctoPrint/wiki/Webcams-known-to-work for clues for parameters to pass to mjpg-streamer for your camera. If you are lucky, you may not need them.
eg. for my Logitech C920
sudo mjpg_streamer -i "input_uvc.so -r VGA -f 10" -o output_http.so
If all is good, you should be able to watch the stream in a browser from
http://IP_ADDRESS_OF_PI:8080/?action=stream
camera:
- platform: mjpeg
mjpeg_url: http://IP_ADDRESS_OF_PI:8080/?action=stream