Encoding multiple video streams with a single avconv invocation

Posted by automatthias on Super User See other posts from Super User or by automatthias
Published on 2012-12-01T13:43:30Z Indexed on 2012/12/19 23:06 UTC
Read the original article Hit count: 287

Filed under:
|

I played with avconv on Ubuntu and I'm now able to e.g. record the desktop with sound from a soundcard. One thing I wanted to do was recording two video inputs at the same time, for instance the desktop and from the webcam. I thought about doing something like this:

avconv \
  -f alsa \
  -i default \
  -acodec flac \
  -f video4linux2 \
  -r 6 \
  -i /dev/video0 \
  -f x11grab \
  -i :0.0 \
  out.mkv

My thinking was that if you define multiple video inputs, and the .mkv format can handle multiple video streams, avconv will encode 2 video streams and 1 audio stream into one file. But this isn't what happens:

avconv version 0.8.4-6:0.8.4-0ubuntu0.12.10.1, Copyright (c) 2000-2012 the Libav developers
  built on Nov  6 2012 16:51:11 with gcc 4.7.2
[alsa @ 0x1091bc0] capture with some ALSA plugins, especially dsnoop, may hang.
[alsa @ 0x1091bc0] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'default':
  Duration: N/A, start: 1354364317.020350, bitrate: N/A
    Stream #0.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[video4linux2 @ 0x10923e0] Estimating duration from bitrate, this may be inaccurate
Input #1, video4linux2, from '/dev/video0':
  Duration: N/A, start: 100607.724745, bitrate: 29491 kb/s
    Stream #1.0: Video: rawvideo, yuyv422, 640x480, 29491 kb/s, 6 tbr, 1000k tbn, 6 tbc
[x11grab @ 0x107b2a0] device: :0.0+83,87 -> display: :0.0 x: 83 y: 87 width: 854 height: 480
[x11grab @ 0x107b2a0] shared memory extension  found
[x11grab @ 0x107b2a0] Estimating duration from bitrate, this may be inaccurate
Input #2, x11grab, from ':0.0+83,87':
  Duration: N/A, start: 1354364318.488382, bitrate: 196761 kb/s
    Stream #2.0: Video: rawvideo, bgra, 854x480, 196761 kb/s, 15 tbr, 1000k tbn, 15 tbc
Incompatible pixel format 'bgra' for codec 'mpeg4', auto-selecting format 'yuv420p'
[buffer @ 0x107fcc0] w:854 h:480 pixfmt:bgra
[avsink @ 0x10bdf00] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x10dc680] w:854 h:480 fmt:bgra -> w:854 h:480 fmt:yuv420p flags:0x4
Output #0, matroska, to '.../out.mkv':
  Metadata:
    encoder         : Lavf53.21.0
    Stream #0.0: Video: mpeg4, yuv420p, 854x480, q=2-31, 4000 kb/s, 1k tbn, 15 tbc
    Stream #0.1: Audio: libvorbis, 48000 Hz, 2 channels, s16
Stream mapping:
  Stream #2:0 -> #0:0 (rawvideo -> mpeg4)
  Stream #0:0 -> #0:1 (pcm_s16le -> libvorbis)
Press ctrl-c to stop encoding
[mpeg4 @ 0x10bd800] rc buffer underflow
^Cframe=  160 fps= 15 q=2.0 Lsize=    3414kB time=10.66 bitrate=2623.0kbits/s    
video:3273kB audio:131kB global headers:4kB muxing overhead 0.165600%
Received signal 2: terminating.

I'm not sure if it's the question of mapping (some -map options to add?) or that avconv just can't encode more than 1 video stream at one time. So is it an actual avconv limitation, or a limitation of the available containers, or me simply not finding the right combination of command line options?

© Super User or respective owner

Related posts about video-capture

Related posts about avconv