webcam recording

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

webcam recording

Joshua N Pritikin
Can I get some help recording my webcam?

I followed the instructions at:

http://www.buberel.org/serendipity/index.php?/archives/263-But-wait,-theres-more-to-using-a-webcam-on-Linux!.html

I tried video and audio separately.

gst-launch-0.10 alsasrc device="hw:0,0" ! audio/x-raw-int,rate=16000,channels=1,depth=16 ! audioconvert ! alsasink

gst-launch-0.10 v4l2src ! video/x-raw-yuv,width=352 ! ffmpegcolorspace  ! xvimagesink

They work fine. However, when i record them together the video is either
too slow (stamp sync-margin=1 sync-interval=1) or too fast (stamp
sync-margin=2 sync-interval=5).

gst-launch-0.10  v4l2src queue-size=16 ! image/jpeg,width=352,framerate=30/1 \
    ! stamp sync-margin=2 sync-interval=5  \
    ! queue2 max-size-buffers=10000 max-size-bytes=0 max-size-time=0   \
    ! ffdec_mjpeg \
    ! ffmpegcolorspace ! theoraenc quality=60 name=venc alsasrc device="hw:0"  \
    ! audio/x-raw-int,rate=44100 ! audioconvert \
    ! queue2 max-size-buffers=10000 max-size-bytes=0 max-size-time=0 \
    !  vorbisenc quality=0.9 name=aenc oggmux name=mux \
    ! filesink location=out.ogg aenc. ! mux. venc. ! mux.

This is on Ubuntu Hardy. Gstreamer 0.10.18-4ubuntu1 and Gentrans
compiled from source from sourceforge.

T:  Bus=07 Lev=01 Prnt=01 Port=05 Cnt=01 Dev#=  4 Spd=480 MxCh= 0
D:  Ver= 2.00 Cls=ef(unk. ) Sub=02 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=05a9 ProdID=2640 Rev= 1.00
S:  Manufacturer=OmniVision Technologies, Inc. -2640-07.07.20.3
S:  Product=Laptop Integrated Webcam
C:* #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=500mA
A:  FirstIf#= 0 IfCount= 2 Cls=0e(video) Sub=03 Prot=00
I:* If#= 0 Alt= 0 #EPs= 1 Cls=0e(video) Sub=01 Prot=00 Driver=uvcvideo
E:  Ad=83(I) Atr=03(Int.) MxPS=   8 Ivl=4096ms
I:* If#= 1 Alt= 0 #EPs= 0 Cls=0e(video) Sub=02 Prot=00 Driver=uvcvideo
I:  If#= 1 Alt= 1 #EPs= 1 Cls=0e(video) Sub=02 Prot=00 Driver=uvcvideo
E:  Ad=81(I) Atr=05(Isoc) MxPS=1020 Ivl=125us

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: webcam recording

Joshua N Pritikin
On Sun, Jun 15, 2008 at 03:04:31PM -0700, Joshua N Pritikin wrote:
> gst-launch-0.10 alsasrc device="hw:0,0" ! audio/x-raw-int,rate=16000,channels=1,depth=16 ! audioconvert ! alsasink

Oops, I meant:

gst-launch-0.10 alsasrc device="hw:0,0" ! audio/x-raw-int,rate=44100 ! audioconvert ! alsasink

> They work fine. However, when i record them together the video is either
> too slow (stamp sync-margin=1 sync-interval=1) or too fast (stamp
> sync-margin=2 sync-interval=5).

Actually the video seems to be consistently too fast. I can't remember
how I got the video to be too slow.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: webcam recording

Andy Wingo
In reply to this post by Joshua N Pritikin
Hi Joshua,

Long time. Hope you are well.

On Mon 16 Jun 2008 00:04, Joshua N Pritikin <[hidden email]> writes:

> gst-launch-0.10  v4l2src queue-size=16 ! image/jpeg,width=352,framerate=30/1 \
>     ! stamp sync-margin=2 sync-interval=5  \
>     ! queue2 max-size-buffers=10000 max-size-bytes=0 max-size-time=0   \
>     ! ffdec_mjpeg \
>     ! ffmpegcolorspace ! theoraenc quality=60 name=venc alsasrc device="hw:0"  \
>     ! audio/x-raw-int,rate=44100 ! audioconvert \
>     ! queue2 max-size-buffers=10000 max-size-bytes=0 max-size-time=0 \
>     !  vorbisenc quality=0.9 name=aenc oggmux name=mux \
>     ! filesink location=out.ogg aenc. ! mux. venc. ! mux.

I think you will need a videorate in the v4l2 pipeline. That way your
video will dup or drop frames, as appropriate, while your audio stays
constant. I think anyway, I can't remember. I'm sure someone will
correct me if I'm wrong.

Cheers,

Andy
--
http://wingolog.org/

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: webcam recording

Mark Nauwelaerts-2
In reply to this post by Joshua N Pritikin

The pipeline you mentioned originally seems a bit complicated.
The following is my "favourite" one:
     v4l2src queue-size=15 \
       ! stamp silent=false progress=0 sync-margin=2 sync-interval=25 \
       ! video/x-raw-yuv,width=384,height=288,framerate=25/1 \
       ! queue max-size-buffers=0 max-size-bytes=0 max-size-time=4000000000 \
       ! theoraenc quality=32 ! oggmux name="mux" \
       ! filesink location=output.ogg \
     alsasrc latency-time=40000 buffer-time=4000000 \
       ! audio/x-raw-int,rate=48000,width=16,depth=16,channels=2 \
       ! queue max-size-buffers=0 max-size-bytes=0 max-size-time=4000000000 \
       ! audioconvert ! vorbisenc quality=0.5 ! mux.
(yes, the latency and buffer times are likely way overkill, they get adjusted
internally anyway, I'll take anything I can get there short of trying to fit the
entire recording in it, as in the original pipeline :) ..., just as with the
queues.  It is also highly adjusted to the tv capture card hardware in question)

A variation on the above one (different codecs, to give CPU a chance to keep up)
handles hours of uninterrupted capture with impeccable sync, and the one above
also has a/v sync just fine (though not the best possible video quality, due to
settings).  If one is wondering, stamp acts like videorate for formats needing
it, just uses a different approach/algorithm, and restricted to specific cases.

A somewhat looser version of it (among many possible) could then be:
     v4l2src queue-size=15 \
       ! stamp silent=false progress=0 sync-margin=2 sync-interval=5 \
       ! video/x-raw-yuv,width=384,height=288,framerate=20/1 \
       ! queue max-size-buffers=0 max-size-bytes=0 max-size-time=4000000000 \
       ! ffmpegcolorspace ! theoraenc quality=32 ! oggmux name="mux" \
       ! filesink location=output.ogg \
     alsasrc latency-time=40000 buffer-time=4000000 \
       ! audio/x-raw-int,rate=48000 \
       ! queue max-size-buffers=0 max-size-bytes=0 max-size-time=4000000000 \
       ! audioconvert ! vorbisenc quality=0.5 ! mux.
(well, (frame)rates might need adjusting here and there)
That should also handle other sync in v4l2src instances, e.g. webcam, though
have no (working) hardware to test the latter case.

Other thoughts and comments I can come up with:
- sync-margin=1 sync-interval=1 is not recommended;
if "heavy" sync forcing is really needed, sync-interval=2 sync-interval=2 or
something else in between extremes should do (though having to use this seems
already indicative of hardware in trouble)
- try a different container, e.g. matroskamux. In fact, since matroska records
time much more faithfully, there should be no need for fancy sync bits (such as
stamp, videorate)
- some variations in the capture parameters (??), framerate, size, etc
(might make hardware happier)
- I typically use entrans (rather than gst-launch) to run those pipelines;
this should make no difference at all w.r.t. a/v sync, but it has facilities
that e.g. monitor queue levels (to see if anything is choking along the way) and
has proper EOS handling upon SIGINT (which most formats need to end up with a
nicely playable result, e.g. matroska above)

Hopefully did not copy-and-paste error on some of the pipelines ...

Regards,
Mark.

Joshua N Pritikin wrote:

> On Sun, Jun 15, 2008 at 03:04:31PM -0700, Joshua N Pritikin wrote:
>> gst-launch-0.10 alsasrc device="hw:0,0" ! audio/x-raw-int,rate=16000,channels=1,depth=16 ! audioconvert ! alsasink
>
> Oops, I meant:
>
> gst-launch-0.10 alsasrc device="hw:0,0" ! audio/x-raw-int,rate=44100 ! audioconvert ! alsasink
>
>> They work fine. However, when i record them together the video is either
>> too slow (stamp sync-margin=1 sync-interval=1) or too fast (stamp
>> sync-margin=2 sync-interval=5).
>
> Actually the video seems to be consistently too fast. I can't remember
> how I got the video to be too slow.
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: webcam recording

Joshua N Pritikin
On Mon, Jun 16, 2008 at 11:40:25PM +0200, Mark Nauwelaerts wrote:
> - some variations in the capture parameters (??), framerate, size, etc
> (might make hardware happier)

Thanks for your many suggestions.

Even though my camera claims to provide 30 fps, I suspect that it is
actually providing 10 fps. I made some attempt to measure the frame
rate, but I was unsuccessful:

entrans --progress-fps -- --raw v4l2src queue-size=16 \
  ! video/x-raw-yuv,width=352 ! queue ! dam \
  ! ffmpegcolorspace ! xvimagesink

SystemError: error return without exception set
<<<< Now reached PLAYING state >>>>
SystemError: error return without exception set

I tried many variations on that theme. What is the proper way to
diagnose such problems?

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: webcam recording

Mark Nauwelaerts-2
Joshua N Pritikin wrote:

> On Mon, Jun 16, 2008 at 11:40:25PM +0200, Mark Nauwelaerts wrote:
>> - some variations in the capture parameters (??), framerate, size, etc
>> (might make hardware happier)
>
> Thanks for your many suggestions.
>
> Even though my camera claims to provide 30 fps, I suspect that it is
> actually providing 10 fps. I made some attempt to measure the frame
> rate, but I was unsuccessful:
>
> entrans --progress-fps -- --raw v4l2src queue-size=16 \
>   ! video/x-raw-yuv,width=352 ! queue ! dam \
>   ! ffmpegcolorspace ! xvimagesink

The caps that are being used should be displayed in the section PIPELINE CAPS
(at least if there isn't a problem such as you mentioned below),
which is a more organized version of what gst-launch would spit out with -v
option.  This caps info should contain the framerate that is being
auto-negotiated.  You could also run the pipeline with GST_DEBUG="v4l2src:3" (or
maybe it is 4?).  The generated debug output should contain the formats/caps the
element expects the hardware to be able to handle (by having queried it).
(btw; also better make sure you have at least a v4l2src with property
always-copy=true (default), my hardware(driver) at least did not seem to like
the other case).

>
> SystemError: error return without exception set
> <<<< Now reached PLAYING state >>>>
> SystemError: error return without exception set
>
> I tried many variations on that theme. What is the proper way to
> diagnose such problems?

Hm, good question, this exception stuff seems to be a very weird bug I just
noticed yesterday, and I only know so far it is not entirely entrans' fault [*].
In this particular case, you can workaround it by adding
--ignore-prop '.*sink.*' to the options
(works in my setting, if needed try --ignore-prop '...*')

Regards,
Mark

[*] That particular problem was diagnosed by diving into the source code (no
substitute there ;) ) and seeing where the exception occurred.  Turns out I can
reproduce the error as follows:
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gst
>>> f = gst.element_factory_make ('filesink')
>>> b = f.get_property('last_buffer')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
SystemError: error return without exception set
>>> n = f.get_property('name')

No idea why/how yet, probably something going wrong in the sink - GObject -
pygobject chain if the GstMiniObject is NULL.  According to specs, I might get
None here, but not some strange python exception.  Anyway, I expect it will
similarly also affect other sinks with that property, though the work-around
should cover that.  I had not noticed this so far because I usually run entrans
with a default config file that contains a.o. following snippet, so it never
queries sinks for their props:
[options]
ignore-prop=.*sink.*,dam.*,queue.*,identity.*,.*decodebin.*
display-prop=.*\.tag,.*\.bitrate$,.*bframes,.*quantizer,.*\.pass,.*\.queue-size

>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
>


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel