Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 25 Sep 2018, 01:16
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Install a webcam in Slacko 5.3
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 2 [22 Posts]   Goto page: Previous 1, 2
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1619
Location: Japan

PostPosted: Sun 09 Jul 2017, 05:52    Post subject:  

greengeek wrote:
Most of the answers I have seen seem to require v4l2-ctl utility but I don't have it in my system
So do I, but this utility is not necessary.
This lists the attached cameras :
Code:
# cat  /sys/class/video4linux/*/name
ELECOM UCAM-DLK130T
HP Webcam-50

Funny, yesterday my external ELECOM webcam was video1, today it's on top of the list, i.e in directory video0. Might depend of the timing of its plug in and makes it even more inportant to check the parameter.

This should do. Takes a single shot with my webcam:
Code:
#!/bin/bash
CAMERA=ELECOM
VIDEOx=$(grep -rH "$CAMERA" /sys/class/video4linux/*/name | cut -d/ -f5)
ffmpeg -f video4linux2 -s 640x480 -i /dev/$VIDEOx -vframes 1 /tmp/$(date +%T)_$CAMERA.jpg


Edit: Fixed grep command

Last edited by MochiMoppel on Mon 10 Jul 2017, 04:54; edited 1 time in total
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5184
Location: Republic of Novo Zelande

PostPosted: Sun 09 Jul 2017, 13:19    Post subject:  

MochiMoppel wrote:
This should do. Takes a single shot with my webcam:
Code:
#!/bin/bash
CAMERA=ELECOM
VIDEOx=$(grep -r "$CAMERA" /sys/class/video4linux/*/name | cut -d/ -f5)
ffmpeg -f video4linux2 -s 640x480 -i /dev/$VIDEOx -vframes 1 /tmp/$(date +%T)_$CAMERA.jpg

I was not able to get this to work for my Chicony webcam. It returned an error that /dev/Chicony was not found (it's not there of course - it should have been looking for /dev/video0 or video1 instead.

I tried using the line:
Code:
grep -r "Chicony" /sys/class/video4linux/*/name | cut -d/ -f5
to see what it produced but it returned nothing for me. Is that line trying to identify the "0" or "1" to be grafted into "VIDEOx"?
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1619
Location: Japan

PostPosted: Sun 09 Jul 2017, 21:08    Post subject:  

Aaah...I know what's wrong. Works only with both video0 and video1 directories present. Your Chicony is probably the only camera attached, so there will be only one directory.

Change grep -r to grep -rH
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5184
Location: Republic of Novo Zelande

PostPosted: Mon 10 Jul 2017, 04:32    Post subject:  

Excellent, many thanks.
Code:
# grep -rH "Chicony" /sys/class/video4linux/*/name | cut -d/ -f5
video0
#
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5184
Location: Republic of Novo Zelande

PostPosted: Mon 10 Jul 2017, 05:06    Post subject:  

That works nicely - with the exception that the first frame from my camera is very dark. This is apparently because the camera has to run several frames to adjust it's autoexposure, so I tried changing the frames parameter to 10 with the intention of seeing how many frames it takes to lighten up to a satisfactory state. However I got only one frame (too dark again) and the following messages in terminal:
Code:
# ./camshot
ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 16 2013 10:17:34 with gcc 4.7.1 (GCC)
  configuration: --prefix=/usr --cpu=i686 --enable-libmp3lame --enable-libx264 --enable-libfaac --enable-pthreads --enable-small --enable-postproc --enable-libvorbis --enable-gpl --enable-shared --enable-nonfree --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-debug --enable-bzlib --enable-zlib --enable-libspeex --enable-version3 --enable-runtime-cpudetect --enable-x11grab --enable-libdc1394 --enable-libschroedinger --enable-libtheora --enable-libxvid --enable-swscale --enable-libvpx
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 2156.844362, bitrate: 147456 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Output #0, image2, to '/tmp/20:50:48_Chicony.jpg':
  Metadata:
    encoder         : Lavf55.12.100
    Stream #0:0: Video: mjpeg, yuvj422p, 640x480, q=2-31, 200 kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mjpeg)
Press [q] to stop, [?] for help
[image2 @ 0x8081260] Could not get frame filename number 2 from pattern '/tmp/20:50:48_Chicony.jpg' (either set updatefirst or use a pattern like %03d within the filename pattern)
av_interleaved_write_frame(): Invalid argument
#


Any thoughts how multiple frames could be gathered? I would like to throw out all of the dark frames and just grab the first clear one - which is probably about frame 8 judging by my previous multiframe tests using the following:
Code:
mplayer tv:// -tv driver=v4l2:device=/dev/video0:width=1600:height=1200:outfmt=rgb24 -frames 12 -vo jpeg
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1619
Location: Japan

PostPosted: Mon 10 Jul 2017, 23:16    Post subject:  

Maybe this already helps:
Aunt Google wrote:
ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 /tmp/out.jpg

The -ss parameter is used to allow the device to start up correctly. Here in my tests, there is a fade-in effect while the camera is being turned on, so, if I just omit -ss 2, the captured frame will be very dark.

At least it helped me. When taking consecutive shots at 1 frame/sec the first 2 pictures turn out too dark. I noticed that ffmpeg takes 3 pictures rapidly before adjusting to the 1 per second rate, which may explain the dark (under exposed) shots.

I also discovered that I can take less than 1 picture per second.
This will take 30 consecutive pictures, one every 2 seconds. Names start with shot-0001.jpg:
Code:
ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -ss 2 -vf fps=0.5 -vframes 30 /tmp/shot-%04d.jpg
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5184
Location: Republic of Novo Zelande

PostPosted: Tue 11 Jul 2017, 14:57    Post subject:  

Awesome. That is great.
cheers!
Code:

#!/bin/bash
#Test script to take PC webcam images using MochiMoppel code from
#http://www.murga-linux.com/puppy/viewtopic.php?p=960402#960402
#Substitute the name of your preferred webcam (you may have more than one)
#Find your webcam name by opening a terminal and typing the following:
#lsusb
#Note: multiple uses of the script will overwrite previous images.
CAMERA=Chicony
VIDEOx=$(grep -rH "$CAMERA" /sys/class/video4linux/*/name | cut -d/ -f5)
ffmpeg -f video4linux2 -s 640x480 -i /dev/$VIDEOx -ss 2 -vf fps=0.5 -vframes 5 /tmp/shot-%04d.jpg


The only problem is it appears to generate images of a rather dishevelled looking individual sitting in my living room hunched over a keyboard. Ugly.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 2 [22 Posts]   Goto page: Previous 1, 2
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0554s ][ Queries: 12 (0.0148s) ][ GZIP on ]