linuxgstreamerwavusb-camera

using gst-launch-1.0 to record audio to an audio file from any pipewiresrc input


I'm trying to record my camera's audio into an audio file, i tired wav or mp3 with lame and twolame but the results are the same, so lets stick to wav file for now.

I'm on gentoo linux with kernel 6.7.6-gentoo with hyprland (and wayland)

so running st-device-monitor-1.0 Audio/Source shows:

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 ! ...

now.. running gst-launch-1.0 pipewiresrc target-object=67 ! autoaudiosink does work, i can hear the sound from my camera

now i'm trying to record it to a wav file (i added debug output):

gst-launch-1.0 --gst-debug-level=3 pipewiresrc target-object=67 ! audioconvert ! audioresample ! wavenc ! filesink location=output.wav

I get:

Setting pipeline to PAUSED ...
0:00:00.011095507 110033 0x7fe5e4000b70 FIXME                default gstutils.c:4036:gst_pad_create_stream_id_internal:<pipewiresrc0:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
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/
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: pipewireclock0
Redistribute latency...
0:00:00.0 / 99:99:99. <- and it's stuck here

this error is weird video-info video-info.c:540:gst_video_info_from_caps: wrong name 'audio/x-raw', expected video/ or image/ since it's an audio source.

any ideas?

update

it seems like any device that i choose using pipewire src provides the same error.

even when I use my built in Audio:

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 ! ...

and when I run

gst-launch-1.0 --gst-debug-level=3 pipewiresrc target-object=1146 ! audioconvert ! audioresample ! wavenc ! filesink location=output.wav

i get the same error:

0:00:00.033190751 1873059 0x7f1d98002550 ERROR             video-info video-info.c:540:gst_video_info_from_caps: wrong name 'audio/x-raw', expected video/ or image/

i'm using gstreamer 1.22.3 with pipewire 1.0.4 on gentoo linux.

what am I missing ?


Solution

  • I just tested your pipeline on Ubuntu 22.04 with GStreamer 1.20.3, and I'm seeing the exact same behaviour (pipeline gets stuck at 0:00:00.0 / 99:99:99.)

    The exact same pipeline works for me if I replace pipewiresrc with either alsasrc or pulsesrc, and if I throw in an identity dump=true, I can see that the buffers produced by Pipewire are noticeably larger than those from ALSA or Pulse. Unfortunately, the blocksize parameter for pipewiresrc doesn't seem to have an effect for me. Also, if you use gst-launch-1.0 -tv ..., you can see the caps used by the individual elements, and Pipewire seems to prefer F32LE/48kHz, while Pulse and ALSA use S16LE/44.1kHz. Forcing the caps doesn't do anything either, though.

    So the best workaround I can offer right now would be to simply use alsasrc or pulsesrc instead of pipewiresrc. I would actually assume this is a bug related to not streaming into a live sink.