使用gst-launch-1.0从PipeWire源录制音频到WAV文件遇错求助
问题:GStreamer录制PipeWire音频源时出现video-info错误
环境信息
- Gentoo Linux,内核版本6.7.6-gentoo
- 桌面环境:Hyprland(基于Wayland)
- GStreamer 1.22.3、PipeWire 1.0.4
核心现象
通过pipewiresrc播放音频(pipewiresrc target-object=67 ! autoaudiosink)正常,但录制音频到WAV文件时,执行以下命令:
gst-launch-1.0 --gst-debug-level=3 pipewiresrc target-object=67 ! audioconvert ! audioresample ! wavenc ! filesink location=output.wav
会触发错误:
0:00:00.017102534 110033 0x7fe5dc002500 ERROR video-info video-info.c:540:gst_video_info_from_caps: wrong name 'audio/x-raw', expected video/ or image/
且录制进程卡在0:00:00.0 / 99:99:99.状态。该问题不仅出现在摄像头音频源,内置音频源也会触发相同错误。
设备信息
摄像头音频源(st-device-monitor-1.0 Audio/Source输出)
Device found: name : HD Pro Webcam C920 Analog Stereo class : Audio/Source caps : audio/x-raw, layout=interleaved, format=S16LE, rate=[ 16000, 32000 ], channels=2 properties: alsa.card = 1 alsa.card_name = HD Pro Webcam C920 alsa.class = generic alsa.device = 0 alsa.driver_name = snd_usb_audio alsa.id = USB Audio alsa.long_card_name = HD Pro Webcam C920 at usb-0000:00:14.0-10.2, high speed alsa.name = USB Audio alsa.resolution_bits = 16 alsa.subclass = generic-mix alsa.subdevice = 0 alsa.subdevice_name = subdevice #0 api.alsa.card.longname = HD Pro Webcam C920 at usb-0000:00:14.0-10.2, high speed api.alsa.card.name = HD Pro Webcam C920 api.alsa.path = front:1 api.alsa.pcm.card = 1 api.alsa.pcm.stream = capture audio.channels = 2 audio.position = FL,FR card.profile.device = 0 device.api = alsa device.class = sound device.id = 55 device.profile.description = Analog Stereo device.profile.name = analog-stereo device.routes = 1 factory.name = api.alsa.pcm.source media.class = Audio/Source node.description = HD Pro Webcam C920 Analog Stereo node.name = alsa_input.usb-046d_HD_Pro_Webcam_C920_B71E5BFF-02.analog-stereo node.nick = HD Pro Webcam C920 node.pause-on-idle = false object.path = alsa:pcm:1:front:1:capture priority.driver = 2009 priority.session = 2009 factory.id = 18 clock.quantum-limit = 8192 client.id = 32 node.driver = true factory.mode = split audio.adapt.follower = library.name = audioconvert/libspa-audioconvert object.id = 63 object.serial = 67 gst-launch-1.0 pipewiresrc target-object=67 ! ...
内置音频源(st-device-monitor-1.0 Audio/Source输出)
Device found: name : Built-in Audio Analog Stereo class : Audio/Source caps : audio/x-raw, layout=interleaved, format={ (string)S32LE, (string)S16LE }, rate=[ 44100, 192000 ], channels=2 properties: alsa.card = 0 alsa.card_name = HDA Intel PCH alsa.class = generic alsa.device = 0 alsa.driver_name = snd_hda_intel alsa.id = ALC897 Analog alsa.long_card_name = HDA Intel PCH at 0x4406220000 irq 247 alsa.name = ALC897 Analog alsa.resolution_bits = 16 alsa.subclass = generic-mix alsa.subdevice = 0 alsa.subdevice_name = subdevice #0 api.alsa.card.longname = HDA Intel PCH at 0x4406220000 irq 247 api.alsa.card.name = HDA Intel PCH api.alsa.path = front:0 api.alsa.pcm.card = 0 api.alsa.pcm.stream = capture audio.channels = 2 audio.position = FL,FR card.profile.device = 0 device.api = alsa device.class = sound device.id = 56 device.profile.description = Analog Stereo device.profile.name = analog-stereo device.routes = 3 factory.name = api.alsa.pcm.source media.class = Audio/Source node.description = Built-in Audio Analog Stereo node.name = alsa_input.pci-0000_00_1f.3.analog-stereo.3 node.nick = ALC897 Analog node.pause-on-idle = false object.path = alsa:pcm:0:front:0:capture priority.driver = 2009 priority.session = 2009 factory.id = 18 clock.quantum-limit = 8192 client.id = 32 node.driver = true factory.mode = split audio.adapt.follower = library.name = audioconvert/libspa-audioconvert object.id = 91 object.serial = 1146 gst-launch-1.0 pipewiresrc target-object=1146 ! ...
解决方案
该错误是GStreamer的pipewiresrc插件加载了不必要的视频模块,或隐式尝试用视频组件处理音频流导致的,可通过以下方式解决:
1. 显式指定音频Caps,强制音频流处理
在pipewiresrc后直接声明音频格式参数,避免GStreamer误判流类型:
gst-launch-1.0 pipewiresrc target-object=67 ! audio/x-raw,format=S16LE,rate=16000,channels=2 ! audioconvert ! audioresample ! wavenc ! filesink location=output.wav
参数需匹配设备实际支持的Caps(比如摄像头支持16000/32000采样率,内置音频支持44100+)。
2. 使用PipeWire原生工具pw-record录制
绕开GStreamer的兼容性问题,直接用PipeWire原生命令录制:
pw-record --target 67 output.wav
也可通过设备名称指定:
pw-record --device alsa_input.usb-046d_HD_Pro_Webcam_C920_B71E5BFF-02.analog-stereo output.wav
3. 升级GStreamer或PipeWire版本
该错误在GStreamer 1.24+、PipeWire 1.0.5+版本中已修复,Gentoo下可更新相关包:
emerge -av media-libs/gstreamer media-libs/pipewire
4. 调整GStreamer插件依赖(可选)
若坚持使用GStreamer,可在Gentoo下通过USE flags禁用不必要的视频组件,重新构建GStreamer:
echo "media-libs/gstreamer -X -video" >> /etc/portage/package.use/gstreamer emerge -av media-libs/gstreamer
内容的提问来源于stack exchange,提问作者ufk
相关产品推荐
相关产品推荐

