2013-04-16 325 views
3

我的Logitech C920网络摄像机提供以h264编码的视频流。我使用this "capture" tool来访问数据:使用Gstreamer在录制音频+视频时显示无声视频

这样我就可以观看现场视频:

/usr/local/bin/capture -d /dev/video0 -c 100000 -o | \ 
    gst-launch-1.0 -e filesrc location=/dev/fd/0 \ 
        ! h264parse \ 
        ! decodebin\ 
        ! xvimagesink sync=false 

...或者录制的视频流作为原料H264文件:

/usr/local/bin/capture -d /dev/video0 -c 100000 -o | \ 
    gst-launch-0.10 -e filesrc location=/dev/fd/0 \ 
        ! h264parse \ 
        ! mp4mux \ 
        ! filesink location=/tmp/video.mp4 

..但我不能为了我的生活而弄清楚如何在同一时间做到这一点。在录制时在屏幕上播放动态节目有时候会很有用,所以我想做这个工作。 花费时间和小时寻找一种方法来同时抓取和屏幕,但没有运气。与tee s和queue没有太大的关系。

猜猜这将会是ALSA音频(hw:2,0)进入的好处,但我可以用一种丑陋的黑客方式解决这个问题。现在,我得到这个即使HW:2,0是Audacitu或的arecord有效的输入,例如:

Recording open error on device 'hw:2,0': No such file or directory 
Recording open error on device 'plughw:2,0': No such file or directory 

因此,要回顾:很想把那些两个视频比特一起,奖金,如果音频会也工作。我觉得这是一个新手。

在此先感谢您提供的任何帮助。

编辑:非工作代码:

/usr/local/bin/capture -d /dev/video1 -c 100000 -o | \ 
    gst-launch-1.0 -e filesrc location=/dev/fd/0 ! tee name=myvid ! h264parse ! decodebin \ 
    ! xvimagesink sync=false myvid. ! queue ! mux. alsasrc device=plughw:2,0 ! \ 
    audio/x-raw,rate=44100,channels=1,depth=24 ! audioconvert ! queue ! mux. mp4mux \ 
    name=mux ! filesink location=/tmp/out.mp4

...导致这个:

WARNING: erroneous pipeline: could not link queue1 to mux

编辑:尝试umlaeute的建议,得到了几乎是空的视频文件和视频直播一个冻结帧。在音频启用代码中修复两个小错误(双引号错别字,不将音频编码为与MP4兼容的任何东西)之后,使用/不使用音频没有任何差异,但在audioconvert之后添加avenc_aac也没有什么不同。错误输出:

Setting pipeline to PAUSED ... 
Pipeline is live and does not need PREROLL ... 
Setting pipeline to PLAYING ... 
New clock: GstAudioSrcClock 
Redistribute latency... 
ERROR: from element /GstPipeline:pipeline0/GstMP4Mux:mux: Could not multiplex stream. 
Additional debug info: 
gstqtmux.c(2530): gst_qt_mux_add_buffer(): /GstPipeline:pipeline0/GstMP4Mux:mux: 
DTS method failed to re-order timestamps. 
EOS on shutdown enabled -- waiting for EOS after Error 
Waiting for EOS... 
ERROR: from element /GstPipeline:pipeline0/GstFileSrc:filesrc0: Internal data flow error. 
Additional debug info: 
gstbasesrc.c(2809): gst_base_src_loop(): /GstPipeline:pipeline0/GstFileSrc:filesrc0: 
streaming task paused, reason error (-5) 

编辑: 好吧,umlaeute的更正后的代码工作完美,但只有当我使用的转换工具的v4l2src代替。而现在,这意味着抓住MJPEG流而不是H264流。我的鼻子没有皮肤,但我想我更喜欢更现代的工作流程。无论如何,这是实际的工作,输出MJPEG视频文件和实时“取景器”。不完美,但非常可行。感谢你的帮助!当涉及到(例如,使用mp4mux)自动组合多个不同的流

gst-launch-1.0 -e v4l2src device=/dev/video1 ! videorate ! 'image/jpeg, width=1280, height=720, framerate=24/1' ! tee name=myvid \  
     ! queue ! decodebin ! xvimagesink sync=false \  
     myvid. ! queue ! mux.video_0 \  
     alsasrc device="plughw:2,0" ! "audio/x-raw,rate=44100,channels=1,depth=24" ! audioconvert ! lamemp3enc ! queue ! mux.audio_0 \  
     avimux name=mux ! filesink location=/tmp/out.avi
+1

'tee'应该可以正常工作,请张贴非工作管道 –

+0

右,两个部分的对自己的正常工作。我不能做的是让他们一起工作。上面添加了非工作示例(我最好的镜头)。出于好奇, –

+0

为什么你不使用v4l2src而不是捕获工具? – ensonic

回答

0

gstreamer的往往是有点哑。 在这种情况下,您通常应该将流不仅发送到指定的元素,而且发送到特定的填充(使用elementname.padname表示法; element.表示法实际上只是指定元素中“任意”填充的简写)。

此外,你似乎忘了mp4muxer的h264parse(如果你看视频的路径,它真的归结为filesrc ! queue ! mp4mux这可能有点粗糙)。

虽然我不能测试管道,我猜像下面应该做的伎俩:

/usr/local/bin/capture -d /dev/video1 -c 100000 -o | \ 
    gst-launch-1.0 -e filesrc location=/dev/fd/0 ! h264parse ! tee name=myvid \ 
    ! queue ! decodebin ! xvimagesink sync=false \ 
    myvid. ! queue ! mp4mux ! filesink location=/tmp/out.mp4 

音频它可能更复杂,尝试这样的事情(当然假设你可以读取的音频使用alsasrc device="plughw:2,0"元素)

/usr/local/bin/capture -d /dev/video1 -c 100000 -o | \ 
    gst-launch-1.0 -e filesrc location=/dev/fd/0 ! h264parse ! tee name=myvid \ 
    ! queue ! decodebin ! xvimagesink sync=false \ 
    myvid. ! queue ! mux.video_0 \ 
    alsasrc device="plughw:2,0" ! "audio/x-raw,rate=44100,channels=1,depth=24"" ! audioconvert ! queue ! mux.audio_0 \ 
    mp4mux name=mux ! filesink location=/tmp/out.mp4 
+0

非常有希望,谢谢你的建议。它还没有正常工作,但隧道尽头可能有光线。新的代码仍然出错,产生一个48个字节的文件,包含基本的mp4头文件和一帧实时视频。在上面的最后一个编辑中添加了相关的错误输出。 –

相关问题