ffmpeg报错-:ffmpeg报Could not find audio only device with name xxx among source devices of type audio

系统:windows

报错信息:

[dshow @ 0000029c119c1100] Could not find audio only device with name ["Microphone (High Definition Audio Device)"] among source devices of type audio.
[dshow @ 0000029c119c1100] Searching for audio device within video devices for "Microphone (High Definition Audio Device)"
[dshow @ 0000029c119c1100] Could not find audio only device with name ["Microphone (High Definition Audio Device)"] among source devices of type video.
audio="Microphone (High Definition Audio Device)": I/O error

本人想使用python的subprocess,操作ffmpeg,推流电脑的麦克风到rtmp服务器上,

报错的代码:

import subprocess
import os

def push(comman):
    print('push: ',os.getpid())
    child = subprocess.Popen(
        comman,
        shell=False, stdin=subprocess.PIPE, encoding="utf-8")
    child.wait()
if __name__ == '__main__':
    print('main: ',os.getpid())
    rtmp = 'rtmp://122.95.31.117/only/audio'

    comman1 =[
        'ffmpeg', '-y' ,
        '-f', 'dshow' ,
        '-i' ,'audio="Microphone (High Definition Audio Device)"',
        '-sample_rate', '44100',
        '-sample_size', '16',
        '-channels', '1',
        '-acodec', 'aac',
        '-fflags', 'nobuffer',
        '-r', '29.97',
        '-f', 'flv',
        str(rtmp)
        ]
    push(comman1)

解决方法:

将输入的麦克风,'audio="Microphone (High Definition Audio Device)"'

改为:'''audio=Microphone (High Definition Audio Device)'''

使用三括号将麦克风命令括起来,就不会报错了

注意:

subprocess.Popen(comman,shell=False, stdin=subprocess.PIPE, encoding="utf-8")

设置 shell=False。

猜你喜欢

转载自blog.csdn.net/weixin_46371752/article/details/127868380