首页 > 解决方案 > ALSA dsnoop 导致 GStreamer 视频出现问题

问题描述

我正在使用 GStreamer 从带有 picam 模块和 USB 麦克风的 Pi3B 流式传输实时视频/音频。我的最终目标是在实时视频/音频流和作为 python 脚本的输入中使用来自一个 USB 麦克风的音频。我知道这可以通过 ALSA dsnoop 插件来完成,并且已经能够通过 /etc/asound.conf 配置进行演示:

pcm.myTest {
    type dsnoop
    ipc_key 2241234
    slave {
        pcm "hw:1,0"
        channels 1
    }
}

pcm.!default {
        type asym
        playback.pcm {
                type plug
                slave.pcm "hw:0,0"
        }
        capture.pcm {
                type plug
                slave.pcm "myTest"
        }
}

视频/音频流使用以下 GStreamer 设置完美运行,但我无法在其他应用程序中使用麦克风(注意“hw:1,0”):

#!/bin/bash
gst-launch-1.0 -v rpicamsrc vflip=true hflip=false \
               name=src preview=0 fullscreen=0 bitrate=10000000 \
               annotation-mode=time annotation-text-size=20 \
               ! video/x-h264,width=960,height=540,framerate=24/1 \
               ! h264parse \
               ! rtph264pay config-interval=1 pt=96 \
               ! queue max-size-bytes=0 max-size-buffers=0 \
               ! udpsink host=192.168.1.101 port=5001 \
               alsasrc device=hw:1,0 \
               ! audioconvert \
               ! audioresample \
               ! opusenc \
               ! rtpopuspay \
               ! queue max-size-bytes=0 max-size-buffers=0 \
               ! udpsink host=192.168.1.101 port=5002

以下(使用 dsnoop)在视频流中导致了一个问题,看起来像是某种同步问题,而不是每秒 24 帧的平滑问题,我每 2-3 秒得到一帧。音频继续运行良好,我能够在其他应用程序中同时使用 USB 麦克风。

#!/bin/bash
gst-launch-1.0 -v rpicamsrc vflip=true hflip=false \
               name=src preview=0 fullscreen=0 bitrate=10000000 \
               annotation-mode=time annotation-text-size=20 \
               ! video/x-h264,width=960,height=540,framerate=24/1 \
               ! h264parse \
               ! rtph264pay config-interval=1 pt=96 \
               ! queue max-size-bytes=0 max-size-buffers=0 \
               ! udpsink host=192.168.1.101 port=5001 \
               alsasrc device=plug:myTest \
               ! audioconvert \
               ! audioresample \
               ! opusenc \
               ! rtpopuspay \
               ! queue max-size-bytes=0 max-size-buffers=0 \
               ! udpsink host=192.168.1.101 port=5002

我已经尝试了一些我在一些外围相关论坛中发现的东西,但无济于事,我感觉有点卡住了。你们中的任何人对让流与 dsnoop 很好地播放有什么建议,这样我就可以避免为这个项目购买另一个麦克风吗?

谢谢!

标签: linuxraspberry-pistreaminggstreameralsa

解决方案


对于后代,我从GStreamer 开发者论坛收到了一个很棒的提示。

添加provide-clock=false到 alsasrc 行就可以了!所以 GStreamer 调用变为:

#!/bin/bash
gst-launch-1.0 -v rpicamsrc vflip=true hflip=false \
               name=src preview=0 fullscreen=0 bitrate=10000000 \
               annotation-mode=time annotation-text-size=20 \
               ! video/x-h264,width=960,height=540,framerate=24/1 \
               ! h264parse \
               ! rtph264pay config-interval=1 pt=96 \
               ! queue max-size-bytes=0 max-size-buffers=0 \
               ! udpsink host=192.168.1.101 port=5001 \
               alsasrc device=plug:myTest provide-clock=false\
               ! audioconvert \
               ! audioresample \
               ! opusenc \
               ! rtpopuspay \
               ! queue max-size-bytes=0 max-size-buffers=0 \
               ! udpsink host=192.168.1.101 port=5002

这种方法的一个小副作用是音频与视频不同步大约 0.5 秒。我很想知道是否有办法将两者同步得更好一点,或者这只是尝试将 dsnoop 设备与 gstreamer 一起使用时不可避免的权衡之一?


推荐阅读