I like in this article the different Python functions to control a Pi cameras. Can this be done with USB camera?

Or do I always need 3rd party softwares like fswebcam, ffmpeg, motion to do things with USB cameras?

(I really want a way to get to preview the photo I am taking. But motion doesn't have a that feature. So I want to try to make a Python program for that purpose.)

Here is my motion.conf for snapshot:

  • Suggest editing title to ask "How do I trigger on-demand phtoto from a USB video stream?" You've done the research. :D I can think of a horribly hacky way to get motion to do this, but it is truly horrible. Let's see what folks come up with. – OyaMist Jun 7 '18 at 14:14
  • I actually found a link on taking snapshot on command using HTTP control but I don't understand how they input the command into the actual URL: lavrsen.dk/foswiki/bin/view/Motion/MotionHttpAPI – most venerable sir Jun 7 '18 at 18:49
  • I tried it and got a snapshot! OK. Let me write up an answer – OyaMist Jun 7 '18 at 20:49
  • 1
    Yay! We did it? Congrats! :D – OyaMist Jun 8 '18 at 20:40

The motion program can be used to capture a USB video-stream on a Raspberry Pi. It can also take snapshots on demand during a video-stream. Conceptually, motion provides two web services on separate ports that you configure in motion.conf. One web service provides the video stream. The other allows you to control motion itself.

Let's first edit motion.conf to specify a snapshot filename and location to take snapshots every hour. The timestamped snapshots will be files in /home/pi:

target_dir /home/pi
snapshot_filename %Y%m%d-%H%M%S-snap
snapshot_interval 3600
output_pictures off

Now we configure the two ports as follows in motion.conf:

stream_port 8081
stream_localhost off
webcontrol_port 8080
webcontrol_localhost off

Let's also assume that Pi is at IP address 192.X.X.X

With the above configuration, your videostream will be accessible from a browser at:


In addition, you can take a snapshot each time you fetch the following URL:


The above is the gist of what you need to do. Please take time to read the configuration parameters. They are quite numerous but you will soon find yourself experimenting with fun things like motion-triggered movies.

  • where is the snapshot stored inside the computer? What does 1 mean? – most venerable sir Jun 8 '18 at 13:28
  • The 1 in the url is the camera thread number. Pi can only really handle 1 web cam where other computers can handle more. So we always use 1. – OyaMist Jun 8 '18 at 14:15
  • I tried it on the pi browser, because SSH PUTTY doesn't work for now. It said "Not Valid. The requested URL is not valid" Actually, there is a ""back"" button with an arrow. I clicked that. Then there is a "All" button. Then, "action"->"snapshot"->then it says "snapshot for thread 0 done." WHERE IS THE PHOTO? – most venerable sir Jun 8 '18 at 15:50
  • The timestamped photo should be on the Raspberry Pi. I've edited answer. – OyaMist Jun 8 '18 at 16:04
  • I type And then hundreds of snapshot start appearing in my folder, until I close the browser tab. How do I take 1 snapshot? – most venerable sir Jun 8 '18 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.