2014-09-04 184 views
2

我有使用gstreamer錄製流的問題。 我必須分別寫入音頻和視頻,並在信號到達時切入。我有正確的工作視頻,但仍然有wav文件的問題。 即使gst-launch中的簡單管道也無法正常工作。我有波形文件,我試圖用multifilesink拆分它:
gst-launch filesrc location=test.wav ! multifilesink location=test2%d.wav next-file=4 max-file-size=512000 不過,雖然與TS文件相同的管道正在確定最終的WAV文件被損壞:
gst-launch-1.0 filesrc location=test.ts ! multifilesink location=test2%d.ts next-file=4 max-file-size=2000000Gstreamer multifilesink wav文件拆分

+0

使用gst-launch-1.0和gst-launch-0.10 – user3921796 2014-09-04 11:06:54

+0

沒有區別嗨,你能解決這個問題嗎? – 2016-02-26 14:46:14

回答

1

multifilesink不知道什麼的數據分裂,所以它不會爲每個它寫入的文件添加標題。

您的.ts文件工作的原因是因爲它被設計成流式格式,其中每個單獨的數據包將被獨立處理。因此,只要有人喜歡,就可以「調諧」到流中。解碼器將簡單地尋找它找到的下一個分組頭,並在那裏開始解碼文件起始處只有一個標題,當你將文件分割成多個文件時,這些標題就會丟失(這時文件只包含原始的PCM數據)

要解決這個問題,你可以..

  • 手動將.wav標頭從第一個文件複製到所有其他o nes
  • 使用支持PCM文件的程序,並直接與它們一起工作或轉換文件(當您打開這些文件時,您必須手動設置通道數,採樣率和比特率)。
  • 使用另一種面向流的文件格式,如.mp3,它來自與.ts相同的編解碼器系列,並且還爲每個幀使用單獨的4字節標題(請注意,MP3是有損文件格式)。
    一個例子管道是:

    gst-launch filesrc location=test.wav ! wavparse ! lame ! multifilesink location=test%d.mp3 next-file=4 max-file-size=100000 
    
+0

我想要有未壓縮的文件,所以我不能使用mp3。 複製標題也不是個好主意,因爲然後文件不知道它們有多長。有什麼辦法可以將一個wav文件分割爲1分鐘部分使用gstreamer? – user3921796 2014-09-05 07:28:19

0

如果你願意使用一些腳本,以及高達拆分任務分成不同的通話gst-launch,我可以爲您提供了另一種可能的方法來解決你的小問題:

以下腳本是Linux bash腳本。您應該能夠把這一到Windows批處理腳本(或C或Python應用程序,如果你想):

#!/bin/bash -e 

# First write the buffer stream to .buff files (annotated using GStreamer's GDP format) 
gst-launch -e filesrc location=test.wav ! wavparse ! gdppay ! multifilesink next-file=4 max-file-size=1000000 location=foo%05d.buff 

# use the following instead for any other source (e.g. internet radio streams) 
#gst-launch -e uridecodebin uri=http://url.to/stream ! gdppay ! multifilesink next-file=4 max-file-size=1000000 location=foo%05d.buff 

# After we're done, convert each of the resulting files to proper .wav files with headers 
for file in *.buff; do 
    tgtFile="$(echo "$file"|sed 's/.buff$/.wav/')" 

    gst-launch-0.10 filesrc "location=$file" ! gdpdepay ! wavenc ! filesink "location=$tgtFile" 
done 

# Uncomment the following line to remove the .buff files here, but to avoid accidentally 
# deleting stuff we haven't properly converted if something went wrong, I'm not gonna do that now. 
#rm *.buff 

我們什麼腳本的作用:

  • 首先我們要使用multifilesink創建一組.buff文件,每個文件的大小均小於1MB(gdppay將使用其大寫標註每個緩衝區; -e標誌gst-launch將導致它在觸發EOS時提前終止進程,這對於您閱讀和解碼互聯網流)
  • for循環中的第二個gst-launch調用採用.buff文件之一,使用gdpdepay(並去除它們)解析GDP標頭,添加WAV標頭並將結果寫入.wav文件。

希望這是一個您可以接受的解決方案,因爲我懷疑有一種方法可以用一個gst-launch運行。