2013-04-16 208 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頭文件和一幀實時視頻。在上面的最後一個編輯中添加了相關的錯誤輸出。 –