簡體   English   中英

Gstreamer 記錄多段 RTP stream 到文件

[英]Gstreamer recording multiple segments of RTP stream to file

我正在用 gstreamer 編寫一個 c++ 應用程序,並試圖實現以下目標:連接到 rtp 音頻 stream(opus),將整個 stream 的一個副本寫入音頻文件,然后另外,基於用戶觸發的事件, 創建一個單獨的系列音頻文件,由 rtp stream 的片段組成(想想開始/停止記錄切換按鈕)。

目前正在使用 udpsrc -> rtpbin -> rtpopusdepay -> queue -> tee (管道在這里拆分)

tee_stream_1 -> 隊列 -> webmmux -> 文件接收器

tee_stream_2 -> 隊列 -> webmmux -> 文件接收器

tee_stream_1 應該在管道的整個持續時間內處於活動狀態。 tee_stream_2 應該根據用戶切換事件生成多個文件。

示例場景:

  1. 管道接收 rtp 音頻 stream,tee_stream_1 開始將音頻寫入 full_stream.webm
  2. 進入 rtp 音頻 stream 2 秒后,用戶切換“開始錄制”。 tee_stream_2 開始將音頻寫入 stream_segment_1.webm
  3. 進入 rtp 音頻 stream 5 秒后,用戶切換“停止錄制”。 tee_stream_2 完成將音頻寫入 stream_segment_1.webm 並關閉文件。
  4. 進入 rtp 音頻 stream 8 秒后,用戶切換“開始錄制”。 tee_stream_2 開始將音頻寫入 stream_segment_2.webm
  5. 進入 rtp 音頻 stream 9 秒后,用戶切換“停止錄制”。 tee_stream_2 完成將音頻寫入 stream_segment_2.webm 並關閉文件。
  6. 10 秒進入 rtp 音頻 stream,stream 結束,full_stream.webm 完成寫入音頻並關閉。

最終結果是 3 個音頻文件,full_stream.webm 有 10 秒的音頻,stream_segment_1.webm 有 3 秒的音頻,stream_segment_2.webm 有 1 秒的音頻。

到目前為止,這樣做的嘗試遇到了困難,因為復用器似乎需要一個 EOS 事件來正確地完成 stream_segment 文件的寫入,但是這個 EOS 被傳播到管道的其他元素,這具有結束所有流水線的不良影響錄音。 關於如何最好地實現這一目標的任何想法? 如果有幫助,我可以提供代碼。

感謝您提供的所有幫助!

對於這種情況,我建議嘗試使用RidgeRun 的開源 gstd 和 interpipe 插件,它們提供對動態管道的高級控制。

您可以安裝類似的東西:

# Some required packages to be installed, not exhaustive...
# If not enough you would see errors and figure out any other missing package
sudo apt install libsoup2.4-dev libjson-glib-dev libdaemon-dev libjansson-dev libreadline-dev gtk-doc-tools python3-pip

# Get gstd sources from github
git clone --recursive https://github.com/RidgeRun/gstd-1.x.git

# Configure, build and install (meson may be better, but here using autogen/configure
cd gstd-1.x
./autogen.sh 
./configure 
make -j $(nproc)
sudo make install
cd ..


# Get gst-interpipe sources from github
git clone --recursive https://github.com/RidgeRun/gst-interpipe.git

# Configure, build and install (meson may be better, but here using autogen/configure
cd gst-interpipe
./autogen.sh 
./configure 
make -j $(nproc)
sudo make install
cd ..

# Tell gstreamer about the new plugins interpipesink and interpipesrc
# First clear gstreamer cache (here using arm64, you would adapt for your arch)
rm ~/.cache/gstreamer-1.0/registry.aarch64.bin

# add new plugins path
export GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0

# now any gstreamer command would rebuild the cache, so if ok this should work
gst-inspect-1.0 interpipesink

interpipes 需要一個管理的守護進程,所以在第一個終端中你只需啟動它。 如果有的話,它會顯示一些操作和錯誤:

gstd

現在在第二個終端中,您可以嘗試此腳本(此處記錄到目錄 /home/user/tmp/tmp2...根據您的情況進行調整):

#!/bin/sh

gstd-client pipeline_create rtpopussrc udpsrc port=5004 ! application/x-rtp,media=audio,encoding-name=OPUS,clock-rate=48000 ! queue ! rtpbin ! rtpopusdepay ! opusparse ! audio/x-opus ! interpipesink name=opussrc

gstd-client pipeline_create audio_record_full interpipesrc name=audiofull listen-to=opussrc is-live=true allow-renegotiation=true stream-sync=compensate-ts ! queue ! audio/x-opus ! opusparse ! webmmux ! filesink location=/home/user/tmp/tmp2/full_stream.webm


gstd-client pipeline_play rtpopussrc
gstd-client pipeline_play audio_record_full

sleep 2

gstd-client pipeline_create audio_record_1 interpipesrc name=audio_rec1 listen-to=opussrc is-live=true allow-renegotiation=true stream-sync=compensate-ts ! queue ! audio/x-opus ! opusparse ! webmmux ! filesink location=/home/user/tmp/tmp2/stream_segment_1.webm
gstd-client pipeline_play audio_record_1

sleep 3

gstd-client pipeline_stop audio_record_1
gstd-client pipeline_delete audio_record_1

sleep 3

gstd-client pipeline_create audio_record_2 interpipesrc name=audio_rec2 listen-to=opussrc is-live=true allow-renegotiation=true stream-sync=compensate-ts ! queue ! audio/x-opus ! opusparse ! webmmux ! filesink location=/home/user/tmp/tmp2/stream_segment_2.webm
gstd-client pipeline_play audio_record_2

sleep 1

gstd-client pipeline_stop audio_record_2
gstd-client pipeline_delete audio_record_2

sleep 1

gstd-client pipeline_stop audio_record_full
gstd-client pipeline_delete audio_record_full
gstd-client pipeline_stop rtpopussrc
gstd-client pipeline_delete rtpopussrc

echo 'Done'

並檢查生成的文件。

暫無
暫無

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

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