How to use the command pw-loopback (with examples)
- Linux
- December 25, 2023
The pw-loopback command is a tool for creating loopback devices in PipeWire, a server and API for handling audio and video streams. Loopback devices are virtual devices that capture audio from one source and playback audio to another source simultaneously.
Use case 1: Create a loopback device with the default loopback behavior
Code:
pw-loopback
Motivation: This use case would be useful if you simply want to create a loopback device without any specific configuration or customization. It will create a loopback device that behaves according to the default settings.
Explanation:
- The command
pw-loopback
creates a loopback device with the default loopback behavior. - No additional arguments or options are provided.
Example output: The loopback device is created and ready to use.
Use case 2: Create a loopback device that automatically connects to the speakers
Code:
pw-loopback -m '[FL FR]' --capture-props='media.class=Audio/Sink'
Motivation: This use case is useful if you want to create a loopback device that automatically connects to the speakers. By specifying the capture properties as media.class=Audio/Sink
, the loopback device will capture audio from the speakers.
Explanation:
- The option
-m '[FL FR]'
specifies the audio channels to include in the loopback device. In this case, it includes the front left and front right channels. - The option
--capture-props='media.class=Audio/Sink'
sets the capture properties of the loopback device to automatically connect to the speakers.
Example output: The loopback device is created and automatically connected to the speakers.
Use case 3: Create a loopback device that automatically connects to the microphone
Code:
pw-loopback -m '[FL FR]' --playback-props='media.class=Audio/Source'
Motivation: This use case is useful if you want to create a loopback device that automatically connects to the microphone. By specifying the playback properties as media.class=Audio/Source
, the loopback device will playback audio to the microphone.
Explanation:
- The option
-m '[FL FR]'
specifies the audio channels to include in the loopback device. In this case, it includes the front left and front right channels. - The option
--playback-props='media.class=Audio/Source'
sets the playback properties of the loopback device to automatically connect to the microphone.
Example output: The loopback device is created and automatically connected to the microphone.
Use case 4: Create a dummy loopback device that doesn’t automatically connect to anything
Code:
pw-loopback -m '[FL FR]' --capture-props='media.class=Audio/Sink' --playback-props='media.class=Audio/Source'
Motivation: This use case is useful if you want to create a loopback device that doesn’t automatically connect to any specific audio source or destination. By providing both capture and playback properties, the loopback device will still be created, but without any automatic connections.
Explanation:
- The option
-m '[FL FR]'
specifies the audio channels to include in the loopback device. In this case, it includes the front left and front right channels. - The option
--capture-props='media.class=Audio/Sink'
sets the capture properties of the loopback device to specify the desired audio source. - The option
--playback-props='media.class=Audio/Source'
sets the playback properties of the loopback device to specify the desired audio destination.
Example output: The loopback device is created without any automatic connections.
Use case 5: Create a loopback device that automatically connects to the speakers and swaps the left and right channels between the sink and source
Code:
pw-loopback --capture-props='media.class=Audio/Sink audio.position=[FL FR]' --playback-props='audio.position=[FR FL]'
Motivation: This use case is useful if you want to create a loopback device that automatically connects to the speakers and swaps the left and right audio channels between the sink (capture) and source (playback).
Explanation:
- The option
--capture-props='media.class=Audio/Sink audio.position=[FL FR]'
sets both the capture properties and the position of the capture channels. It specifies the audio source as the speakers and includes the front left and front right channels in the loopback device. - The option
--playback-props='audio.position=[FR FL]'
sets the position of the playback channels. It swaps the left and right channels in the loopback device.
Example output: The loopback device is created, automatically connected to the speakers, and the left and right audio channels are swapped.
Use case 6: Create a loopback device that automatically connects to the microphone and swaps the left and right channels between the sink and source
Code:
pw-loopback --capture-props='audio.position=[FR FL]' --playback-props='media.class=Audio/Source audio.position=[FL FR]'
Motivation: This use case is useful if you want to create a loopback device that automatically connects to the microphone and swaps the left and right audio channels between the sink (capture) and source (playback).
Explanation:
- The option
--capture-props='audio.position=[FR FL]'
sets the position of the capture channels. It swaps the left and right channels in the loopback device. - The option
--playback-props='media.class=Audio/Source audio.position=[FL FR]'
sets both the playback properties and the position of the playback channels. It specifies the audio destination as the microphone and includes the front left and front right channels in the loopback device.
Example output: The loopback device is created, automatically connected to the microphone, and the left and right audio channels are swapped.
Conclusion:
The pw-loopback command is a versatile tool for creating loopback devices in PipeWire. It allows you to customize the behavior of loopback devices, including the audio channels, source, and destination. This flexibility makes it a powerful tool for various audio routing and streaming scenarios.