[FFmpeg-user] Webcam capture

Rodolfo Medina rodolfo.medina at gmail.com
Wed Jul 22 21:40:03 EEST 2020


Leonardo via ffmpeg-user <ffmpeg-user at ffmpeg.org> writes:

> Hello,
>
> as an alternative, you can display your webcam at screen with mplayer
>
> $ mplayer tv:// -tv
> driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2
> -noborder -geometry 640x480+0+0
>
> and record your screen+audio with ffmpeg (here I'm using pulseaudio because of
> the "noise-reduction")
>
>
> $ ffmpeg -thread_queue_size 1024 -f pulse -sample_rate 44100 -i default
> -video_size 640x480 -probesize 10M -framerate 30 -thread_queue_size 512 -f
> x11grab -i :0.0 -c:a aac -b:a 128k -c:v libx264 -vf "format=yuv420p" -crf 0
> -preset ultrafast output.mp4
>
> You can use
>
> $ uvcdynctrl -f
>
> to identify which resolution/fps your webcam supports and edit commands above
> to your needs.


Thank you, Leonardo...  but the problem remains: when I watch the resulting
video, it freezes for many seconds at start...

$ uvcdynctrl -f
Listing available frame formats for device video0:
Pixel format: YUYV (YUYV 4:2:2; MIME type: video/x-raw-yuv)
  Frame size: 640x480
    Frame rates: 30, 30
  Frame size: 320x240
    Frame rates: 30
  Frame size: 160x120
    Frame rates: 30
  Frame size: 640x480
    Frame rates: 30, 30



$ mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:fps=30:outfmt=yuy2 -noborder -geometry 640x480+0+0
MPlayer 1.3.0 (Debian), built with gcc-8 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing tv://.
TV file format detected.
Selected driver: v4l2
 name: Video 4 Linux 2 input
 author: Martin Olschewski <olschewski at zpr.uni-koeln.de>
 comment: first try, more to come ;-)
v4l2: your device driver does not support VIDIOC_G_STD ioctl, VIDIOC_G_PARM was used instead.
Selected device: BZ IR: BZ IR
 Capabilities:  video capture  streaming
 supported norms:
 inputs: 0 = Camera 1;
 Current input: 0
 Current format: YUYV
tv.c: norm_from_string(pal): Bogus norm parameter, setting default.
v4l2: ioctl enum norm failed: Inappropriate ioctl for device
Error: Cannot set norm!
Selected input hasn't got a tuner!
v4l2: ioctl set mute failed: Invalid argument
==========================================================================
Opening video decoder: [raw] RAW Uncompressed Video
Movie-Aspect is undefined - no prescaling applied.
VO: [vdpau] 640x480 => 640x480 Packed YUY2 
Selected video codec: [rawyuy2] vfm: raw (RAW YUY2)
==========================================================================
Audio: no sound
Starting playback...
V:   0.0 154/154 ??% ??% ??,?% 0 0 



$ ffmpeg -thread_queue_size 1024 -f pulse -sample_rate 44100 -i default -video_size 640x480 -probesize 10M -framerate 30 -thread_queue_size 512 -f x11grab -i :0.0 -c:a aac -b:a 128k -c:v libx264 -vf "format=yuv420p" -crf 0 -preset ultrafast output.mp4
ffmpeg version 4.1.4-1+b2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9 (Debian 9.2.1-1)
  configuration: --prefix=/usr --extra-version=1+b2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, pulse, from 'default':
  Duration: N/A, start: 1595442907.483712, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Input #1, x11grab, from ':0.0':
  Duration: N/A, start: 1595442908.796004, bitrate: N/A
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
File 'output.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x55b270984840] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX BMI1 SlowPshufb
[libx264 @ 0x55b270984840] profile High 4:4:4 Predictive, level 3.0, 4:2:0 8-bit
[libx264 @ 0x55b270984840] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 640x480, q=-1--1, 30 fps, 15360 tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.35.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.35.100 aac
frame=  419 fps= 44 q=0.0 size=     768kB time=00:00:13.74 bitrate=
457.7kbits/s dup=120 drop=118 speed=1.44x



thanks,

rodolfo


More information about the ffmpeg-user mailing list