如何在Linux中使用PyAV捕获音频?

问题描述 投票:0回答:1

我想使用 python 安装在 ubuntu 22.04 上,捕获音频以流式传输。

我尝试了

av.open(format='alsa', file='default')
av.open(format='pulse', file='default')
,并得到了`ValueError:没有容器格式'alsa'。

那么,我该怎么做才能解决这个问题呢? 谢谢你

python audio alsa pyav aiortc
1个回答
0
投票

试试这个:

    def get_available_cameras(self):

        devices = FilterGraph().get_input_devices()

        available_cameras = {}

        for device_index, device_name in enumerate(devices):
            available_cameras[device_index] = device_name

        return available_cameras

    def create_local_tracks(self):
        global relay, webcam
        options = {"framerate": "30", "video_size": "640x480"}
        camera_name = "video="+self.get_available_cameras()[0]
        webcam = MediaPlayer(camera_name, format='dshow', options=options)
        relay = MediaRelay()
        return relay.subscribe(webcam.video)

© www.soinside.com 2019 - 2024. All rights reserved.