jamesbond
Posts: 17
Joined: Fri Jun 21, 2013 1:13 pm

Record Video from USB Webcam- How to ?

Wed Jul 10, 2013 3:23 pm

Hello all.,
Received my raspberry pi yesterday. and i am now playing with it and doing some tests.
I am using usb webcam as the rpi camera board is out of stock and i am waiting eagerly to buy it.
my question is :
How can i record video on the raspberry pi's sd card from usb webcam ?

I have successfully attached the usb web-camera to rpi and my pi can detect it, tried installing motion and pi can stream using mjpeg to Firefox too.

but i couldn't find any command to record the video from webcam on the sd card .
is this possible ?
i am using iBall Web Camera C 8.0 .
my pi can detect it a "Bus 001 Device 012: ID 0c45:6340 Microdia"

what i am trying to do is record a clip and upload using ftp/samba.

Thanks for your time and input.


Update:
i tried avconv and it gave some errors. then i added the usb power hub to power the webcam , then i fired the same command

Code: Select all

avconv -f video4linux2 -i /dev/video0 video0.avi
and it worked., voila.....recorded video in 640x480 30 fps.
Last edited by jamesbond on Thu Jul 11, 2013 4:26 am, edited 1 time in total.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Record Video from USB Webcam- How to ?

Thu Jul 11, 2013 2:07 am

You can use ffmpeg to record to a file.

Code: Select all

ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

jamesbond
Posts: 17
Joined: Fri Jun 21, 2013 1:13 pm

Re: Record Video from USB Webcam- How to ?

Thu Jul 11, 2013 3:26 am

SirLagz wrote:You can use ffmpeg to record to a file.

Code: Select all

ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
thanks , i tried , it says

Code: Select all

[email protected] ~ $ ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
ffmpeg version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
  built on Mar 31 2013 13:58:10 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Unknown input format: 'v4l2'

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Record Video from USB Webcam- How to ?

Thu Jul 11, 2013 5:00 am

jamesbond wrote:
SirLagz wrote:You can use ffmpeg to record to a file.

Code: Select all

ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
thanks , i tried , it says

Code: Select all

[email protected] ~ $ ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
ffmpeg version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
  built on Mar 31 2013 13:58:10 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Unknown input format: 'v4l2'
try using video4linux2 rather than v4l2
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

jamesbond
Posts: 17
Joined: Fri Jun 21, 2013 1:13 pm

Re: Record Video from USB Webcam- How to ?

Thu Jul 11, 2013 5:18 am

SirLagz wrote:
jamesbond wrote:
SirLagz wrote:You can use ffmpeg to record to a file.

Code: Select all

ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
thanks , i tried , it says

Code: Select all

[email protected] ~ $ ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
ffmpeg version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
  built on Mar 31 2013 13:58:10 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Unknown input format: 'v4l2'
try using video4linux2 rather than v4l2
Thanks its working great.

shakirabbas
Posts: 10
Joined: Thu Feb 27, 2014 7:14 pm

Re: Record Video from USB Webcam- How to ?

Thu Feb 27, 2014 7:23 pm

Below works for me too. However, I get a lot of dropped frames at 25fps 640x480. If I stream using same this resolution using mjpg_streamer, it works just fine while barely consuming any Pi CPU. I don't understand why ffmpeg chews up all the CPU and still cannot record the video without dropping most of the frames. I can barely record at 3fps at 640x480. I would think streaming would be more cpu intensive than recording locally on the Pi. What am I missing?

Code: Select all

ffmpeg -f video4linux2 -r 25 -s 640x480 -i /dev/video0 out.avi
You can see, it only recorded 53 frames and dropped 370 frames.

Code: Select all

frame=   53 fps=  2 q=4.2 Lsize=     211kB time=26.32 bitrate=  65.6kbits/s dup=0 drop=370    

ctslick
Posts: 2
Joined: Thu Apr 03, 2014 9:11 pm

Re: Record Video from USB Webcam- How to ?

Wed May 07, 2014 3:59 pm

I'm having the same issue - ffmpeg / video4linux2 only seems to record at very slow frame rates. I can't seem to find a solution for this....

wrybread
Posts: 20
Joined: Thu May 08, 2014 7:13 pm

Re: Record Video from USB Webcam- How to ?

Fri May 09, 2014 6:16 am

My shot in the dark would be that its a writing issue. That's a lot of data to write to an SD card (if that's where you're writing it), and not all SD cards are created equal. Try using a faster (Class 10 or so) faster SD card and see if that fixes it.

plotino
Posts: 2
Joined: Tue Jun 16, 2015 7:02 am

Re: Record Video from USB Webcam- How to ?

Tue Jul 28, 2015 3:01 pm

wrybread
i have the issue of dropped frames ... it seems the aquisition happens at very low frame rate than provided by command.
i have tried to install Raspbain on a new 32 GB class 10, but does not want to boot at power on.
Do you have any hint about it?

plot


Return to “General discussion”