簡體   English   中英

如何在gstreamer中錄制音頻和視頻

[英]how to record audio and video in gstreamer

我是 gstreamer 的新手,我想同時錄制音頻和視頻,並將其保存為 .mp4 格式,使用網絡攝像頭錄制視頻並使用 MIC 錄制音頻這是我的管道

gst-launch-1.0 -e v4l2src ! 排隊! x264enc! h264解析! 排隊! qtmux0. alsasrc ! '音頻/x-raw,rate=44100,depth=24'! 音頻轉換! 音頻重采樣! 哇塞! 分析! qtmux! 文件接收器位置=test.mp4

當我執行它時,視頻只錄制了 10 秒,甚至沒有錄制音頻,它給出了一些消息,例如

警告:來自元素 /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: 無法足夠快地錄制音頻附加調試信息:gstaudiobasesrc.c(866): gst_audio_base_src_create (): /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Dropped samples.4222 這很可能是因為下游無法跟上並且消耗樣本太慢。

幫我解決這個問題 提前謝謝

嘗試使用以下管道將音頻和視頻錄制到一個文件中。

gst-launch-1.0 -e v4l2src device="/dev/video0" ! videoconvert ! queue ! x264enc tune=zerolatency ! mux. alsasrc device="hw:2" ! queue ! audioconvert ! audioresample ! voaacenc ! aacparse ! qtmux name=mux ! filesink location=test.mp4 sync=false

現在得到了管道,它可以完美地錄制音頻和視頻

這里的管道

gst-launch-1.0 -e v4l2src ! '視頻/x-raw,width=960,height=720,framerate=30/1'! 排隊! x264enc 調諧=零延遲! 多路復用器。 alsasrc ! 音頻/x-raw,width=16,depth=16,rate=44100,channel=1! 排隊! 音頻轉換! 音頻重采樣! 哇塞! 分析! qtmux 名稱=多路復用器! filesink location=test.mp4 sync=false

如果管道中有任何不正確的地方,請告訴我

我最終使用了那個(改編自網絡的隨機回復,抱歉我丟失了來源)

raspivid -t 0 --vflip --hflip -w 1920 -h 1080 -fps 30 --bitrate 14000000 --profile baseline -3d sbs --intra 30 --inline --flush --awb auto --exposure auto --sharpness 0 --contrast -15 --digitalgain 0.0 -o - | gst-launch-1.0 -ve fdsrc num-buffers=-1 ! video/x-h264,width=1920,height=1080,framerate=30/1 ! h264parse ! queue ! smux.video alsasrc device=hw:2,0 ! audio/x-raw,format=S32LE,rate=48000,channel=2 ! audioconvert ! avenc_aac ! aacparse ! queue ! smux.audio_0 splitmuxsink name=smux location=video.mp4 muxer=mpegtsmux

請注意,它用於捕獲立體圖像,您可以刪除“-3d sds”並為單個凸輪調整寬度。 您還可以安全地刪除僅對調試有用的 -ve 並將您的音頻設備硬件更改為您的捕獲卡的編號( $ arecord -l以找出您的卡的 ID)。

我更喜歡使用 qtmux,但由於缺少 raspivid 制作的 h264 流中的 PTS 信息而失敗。 mpegtsmux 很高興。

截至目前,生成的 mpeg 已損壞一半,所有玩家都無法讀取(quicktime 失敗,而 vlc 很高興)。 使用 ffmpeg 重新編碼: ffmpeg -vcodec mpeg4 -b:v 7561k -qscale:v 2 -acodec aac -ac 2 -async 1 -strict experimental ./video2.mp4 -threads 0 -i video.mp4修復了文件。

希望這對某人有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM