gstreamer将audio / mpeg转换为audio / x-raw

时间:2018-04-04 17:52:50

标签: audio gstreamer

什么gstreamer元素会将audio / mpeg的输入转换为audio / x-raw?

背景

我正在尝试如何组装gstreamer管道以从MPEG / TS流中提取一些音频并将其保存在wav文件中。 我可以使用以下方法保存MPEG音频格式的传输流中的音频:

gst-launch-1.0 udpsrc port=1235 caps="application/x-rtp" ! rtpjitterbuffer \
! rtpmp2tdepay ! tsdemux program-number=4352 \
! mpegaudioparse ! queue ! filesink location=audio.mp2

>mediainfo audio.mpg 
General
Complete name                            : audio.mpg
Format                                   : MPEG Audio
File size                                : 169 KiB
Duration                                 : 5 s 400 ms
Overall bit rate mode                    : Constant
Overall bit rate                         : 256 kb/s
FileExtension_Invalid                    : m1a mpa1 mp1 m2a mpa2 mp2 mp3

Audio
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Duration                                 : 5 s 400 ms
Bit rate mode                            : Constant
Bit rate                                 : 256 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Frame rate                               : 41.667 FPS (1152 SPF)
Compression mode                         : Lossy
Stream size                              : 169 KiB (100%)

但我无法弄清楚如何将mpeg音频转换为x-raw / PCM / wav,以便作为原始管道的一部分或通过新管道进行进一步操作。 在我看来,它应该是这样的:

gst-launch-1.0 filesrc location=audio.mp2 ! audio/mpeg ! audioconvert ! wavenc ! filesink location=audio.wav

但是audioconvert期待audio / x-raw因此失败了:

WARNING: erroneous pipeline: could not link filesrc0 to audioconvert0, audioconvert0 can't handle caps audio/mpeg

我不清楚哪些元素可以接受 audio / mpeg 或如何找到它们。 gst-inspect 告诉你插件的功能,但我需要一种方法来列出具有给定src或接收器类型的插件。 gst-inspect 表明 wavparse 可以生成 audio / mpeg mad 可以将其转换为mp3,这两者都不是有帮助的。

我也在假设设计gstreamer管道的一个好方法是使用 gst-launch 快速创建一个正确的命令行,然后将其转换为C ++。但是,这里的大多数文档和问题似乎都是直接从C ++开始的。我在某个地方错过了一个技巧吗?

1 个答案:

答案 0 :(得分:0)

使用libmpg123的MPEG音频插件是mpg123audiodec 见 - https://gstreamer.freedesktop.org/documentation/plugins.html

>gst-inspect-1.0 mpg123audiodec
[snip]
Pad Templates:
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      audio/mpeg
            mpegversion: { 1 }
                  layer: [ 1, 3 ]
                   rate: { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }
               channels: [ 1, 2 ]
                 parsed: true
 [snip]

这最近从“丑陋”的插件转移到了好的插件:

GST-插件-难看-1.14.0 / NEWS

Plugin and library moves

MPEG-1 audio (mp1, mp2, mp3) decoders and encoders moved to -good

Following the expiration of the last remaining mp3 patents in most
jurisdictions, and the termination of the mp3 licensing program, as well
as the decision by certain distros to officially start shipping full mp3
decoding and encoding support, these plugins should now no longer be
problematic for most distributors and have therefore been moved from
-ugly and -bad to gst-plugins-good. Distributors can still disable these
plugins if desired.

In particular these are:

-   mpg123audiodec: an mp1/mp2/mp3 audio decoder using libmpg123
-   lamemp3enc: an mp3 encoder using LAME
-   twolamemp2enc: an mp2 encoder using TwoLAME

使用它的命令行是:

gst-launch-1.0 filesrc location=audio.mp2 ! audio/mpeg ! mpg123audiodec ! wavenc ! filesink location=audio.wav