Кодирование нескольких видеопотоков с помощью одного вызова avconv

3005
automatthias

Я играл с avconv в Ubuntu и теперь могу, например, записывать рабочий стол со звуком из звуковой карты. Одна вещь, которую я хотел сделать, - это запись двух видеовходов одновременно, например, с рабочего стола и с веб-камеры. Я думал о том, чтобы сделать что-то вроде этого:

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

Я думал, что если вы определите несколько видеовходов, а формат .mkv может обрабатывать несколько видеопотоков, avconv закодирует 2 видеопотока и 1 аудиопоток в один файл. Но это не то, что происходит:

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. 

Я не уверен, что это вопрос отображения (некоторые опции -map для добавления?) Или avconv просто не может кодировать более 1 видеопотока одновременно. Так это фактическое ограничение avconv или ограничение доступных контейнеров, или я просто не могу найти правильную комбинацию параметров командной строки?

1
Попробуйте `-map 0: 0 -map 1: 0 -map 2: 0` и посмотрите, что он делает. В основном вам необходимо отобразить все входные потоки (входные данные `0`,` 1`, `2`) в выходной поток. Я не могу протестировать его, так как у меня нет ни `avconv`, ни системы Linux для x11grab, но похоже, что сейчас он записывает только x11grab и аудио. slhck 11 лет назад 0

1 ответ на вопрос

0
evilsoup

It's not a good idea to mix input and output options. Hopefully, you'll notice that avconv is converting your audio to Vorbis rather than FLAC - that's because it thinks you're trying to set that as the audio codec of your video4linux device, and is ignoring it as an invalid option. You'd also be best served using x264 as your video encoder. Since you're using Ubuntu, IIRC you should have it as a part of ubuntu-restricted-extras.

avconv -f alsa -i default -f video4linux2 -r 6 -i /dev/video0 -f x11grab -i 0:0 \ -map 1 -map 2 -map 0 \ -c:a flac -c:v libx264 -crf 23 -preset veryfast output.mkv 

By default, avconv selects only one video stream and one audio stream (and one subtitle stream if there's one there) to output. -map 1 -map 2 -map 0 tells it to take every stream from the first three inputs (it starts counting from 0).

It's not directly relevant to this (since each of your inputs will contain only one stream), but you can also select individual streams from inputs with -map: -map 0:1 will map the second stream from the first audio, -map 1:a will map every audio stream from the second input, -map 2:v:1 will map the second video stream from the third input and -map 3:s will map all the subtitles from the fourth input.

The order in which you use the -map flags matters; in the example above, I've made it so that the audio input is mapped third, by placing that -map last.

If you have problems with x264 slowing down your screen recording (it shouldn't unless you have a borderline-obsolete computer), you can try changing the -preset to superfast or ultrafast, both of which will give you faster/less-CPU-intensive encoding If that doesn't work, you could try using -c:v huffyuv - that's a lossless video codec, the video equivalent of FLAC, and will give you truly ludicrous file sizes; but you can re-encode to a less painfully big codec later.

Похожие вопросы