USB Streaming with Motion



Motion is a very useful and nicely written software if you want to stream or publish a webcam using your pi.
I have not gone through the motion of streaming to youtube but it looks like it is possible... I just did not require it.
It is fairly simple to configure and works with both USB and the raspberry pi camera.
sudo apt-get install motion should be all you need command-wise. It has been a while since I installed, but will verify the next time I create a new pi image.

Camera Output

This is a very limited overview and there is a lot more you can do, but my basic setup was just a web page with the camera and a live stream of the feed.
Both seem to work well with a few adjustments and you can access by hitting separate ports on your pi.
If you do not want to use the default ports, you can set them in the motion.config file. You will have to restart the motion daemon for the ports to come active.

Http Port Examples:

http://localhost:8084 for web or http://localhost:8085

Configuration: motion.config

Using the config file (/etc/motion/motion.config) you can set some variables such as authentication, camera device, etc.
For my simple config there are a few things I set.
webcontrol_authentication: I add a username and password so that the page is not open.
videodevice: default is /dev/video0 but this may change if you also have a pi-camera. I am running only a single usb video. Having multiple may require configuring the camera config files.
v4l2_palette 17 - This uses palette YU12 and was the default when I installed motion.
The other thing I did was changing the names of some of the output files. This limits the amount of files actual gathered for both viewing and sreaming.
For the movie_filename I went with a single file to keep accumulated files from building up.
For picture_filename I went with simply LiveFeed-%q. This limits the amount of images saved. I prefer it to overwrite existing instead of creating new files on a date range. You can leave dated filenames if you need to view historically, but I have no real need for that. This keeps my directory right around 25 files.
I also set snapshot_filename to just lastsnap. Again, no need to accumulate those files.

Image/Video Output

The default output is to the /var/lib/motion directory. You can change this in the config file but will need to insure that the account running the daemon has access to read and write files to a different directory. I believe the default account will be motion. You will want to keep an eye on this location to insure you are not collecting to many files. As mentioned above, this can be controlled via the configuration. If you are not pointing to attached storage, this can eat up your micros SD pretty quick.
These will change case by case depending on the quality of your camera and size of images it is capable of taking. I am currently using a Logitech HD USB camera and the directory maintains fairly consistent at approximately 10MB in size. You can also change the amount of motion in percentage that reflects a change. No reason to continuously capture an image that is not changing which saves on processing power used by the pi. This is probably one of the best features I like about Motion and it seems to work quite well. Hats off to the developers, as I mentioned it is a well written program.

Example config file

Here is an example configuration I am using on my pi 3.