I need some help in recording videos with USB webcams in raspberry pi 2. I am currently using this code to start recording videos:

avconv -f video4linux2 -r 10 -s 1280x768 -i /dev/video0 -y new1.avi

But I don't no, how to stop it automatically using a command.

I am using "pkill" to stop recording currently, but i don't think its a efficient way.

Here is my question:

  • How can i stop recording videos?
  • If there is any other method for recording and stopping videos?

1 Answer 1


Searching the Internet I found what appears to be full documentation on aconv at the following site:


Looking at the docs, it appears that the tool is primarily used to convert video and audio data from one format to another. It primarily assumes that the input is a finite length stream and generates a corresponding resultant converted file. Since your video stream is continuous without obvious termination, it will simply "keep on going". I did notice that the tool has options such as "-t duration" which will terminate the conversion once the output is of a specified duration. That would be one way to terminate the result. What you didn't mention in your original post was how you wanted to stop recording? Is it a manual or automated "stop now" instruction or would a given duration be sufficient? If the later, it appears that the '-t' flag might do just that.

If you need a more generic solution, it appears that the tool called "motion" may be more to your liking. It appears to support external control via REST (HTTP) requests. This means that you can use cURL or similar web tools to send HTTP requests to the demon which will caused it to honor those commands ... for example ... to stop and start recording ... see:


  • Yes, I also have gone through duration options. But i want to stop it like, stop now.
    – Assazzin
    Jan 9, 2016 at 7:28
  • There may simply not be a "nice way" to have the aconv tool stop recording on command. Its purpose seems to be to convert a finite amount of input to a finite amount of output. If you are recording from a live camera and don't have a time limit on the amount of capture ... then the input won't end and aconv doesn't know when to stop.
    – Kolban
    Jan 9, 2016 at 17:24
  • Then there is no other we can do it?
    – Assazzin
    Jan 10, 2016 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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