使用gstreamer将原始音频转换为ogg



以下管道生成一个3kb.ogg文件(我认为它只是一个空容器):

gst-launch-1.0 --gst-debug=3 filesrc location=test.raw
! 'audio/x-raw, format=S16LE, channels=1, rate=32000'
! audioconvert
! vorbisenc
! oggmux
! filesink location=test.ogg

以下是调试输出:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
0:00:00.048490941   813 0x556bf3625000 FIXME               basesink gstbasesink.c:3077:gst_base_sink_default_event:<filesink0> stream-start event without group-id. Consider implementing group-id handling in the upstream elements
0:00:00.048541997   813 0x556bf3625000 WARN            audioencoder gstaudioencoder.c:985:gst_audio_encoder_finish_frame:<vorbisenc0> Can't copy metadata because input buffer disappeared
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
0:00:00.139954729   813 0x556bf3625000 WARN                 basesrc gstbasesrc.c:2400:gst_base_src_update_length:<filesrc0> processing at or past EOS
Got EOS from element "pipeline0".
Execution ended after 0:00:00.091883401
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

当我添加这个wav编码/解码时,我得到了一个好的.ogg文件:

gst-launch-1.0 --gst-debug=3 filesrc location=test.raw
! 'audio/x-raw, format=S16LE, channels=1, rate=32000'
! audioconvert
! wavenc
! wavparse
! audioconvert
! vorbisenc
! oggmux
! filesink location=test.ogg

调试输出:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Redistribute latency...
0:00:00.135676651   822 0x562b3cd64770 FIXME               basesink gstbasesink.c:3077:gst_base_sink_default_event:<filesink0> stream-start event without group-id. Consider implementing group-id handling in the upstream elements
0:00:00.135718946   822 0x562b3cd64770 WARN            audioencoder gstaudioencoder.c:985:gst_audio_encoder_finish_frame:<vorbisenc0> Can't copy metadata because input buffer disappeared
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
0:00:00.219188746   822 0x562b3cd64770 WARN                  wavenc gstwavenc.c:795:gst_wavenc_write_toc:<wavenc0> have no toc
Got EOS from element "pipeline0".
Execution ended after 0:00:00.083921991
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

所以我的问题是:第二条管道是什么,有wavenc!wavparse,假设缺少第一个,是否有更直接的方法来指定它,或者第二个形式实际上是"正确"的方法?

第一个管道很好,因为它与testaudiosrc(audio/x-raw-int)一起工作我假设您未压缩的音频文件必须是未压缩的WAV文件

https://en.wikipedia.org/wiki/List_of_codecs#Audio_compression_formats

Wavenc可以对LPCM进行预处理,并转换为vorbisenc可以使用的东西。我怀疑vorbisenc的数据宽度需要是32或64,这可能是一个亮点。

PCM签名的16位little-endian(S16LE)>
音频转换-将音频转换为不同格式(in:audio/x-raw-int-out:audio/x-raw-int)
wavenc-将原始音频编码为WAV(in:aaudio/x-raw-int-out:aaudio/x-WAV)
wavparse-将.WAV文件解析为原始音频(输入:音频/x-raw-float输出:音频/x-verbis)

gst-launch audiotestsrc num-buffers=50 
! vorbisenc 
! oggmux 
! filesink location=test.ogg
play test.ogg

附录:我下载了你的文件,能够确认你正在进行从16位到32位的未实现流转换。Vorbisenc只接受32位宽度。要回答你最初的问题,不,你不需要wavsparking。这是您正在寻找的高效管道,简化为宽度转换。

gst-launch --gst-debug=2 filesrc location=test.raw 
! audio/x-raw-int, width=16, channels=2, depth=16, rate=16000, endianness=1234, signed=true 
! audioconvert 
! audio/x-raw-float, width=32, channels=2, rate=16000, endianness=1234, signed=true 
! vorbisenc 
! oggmux 
! filesink location=test.ogg

最新更新