【问题标题】:ALSA dsnoop causes issue with GStreamer videoALSA dsnoop 导致 GStreamer 视频出现问题
【发布时间】:2021-07-09 00:09:20
【问题描述】:

我正在使用 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 很好地播放,这样我就可以避免为这个项目购买另一个麦克风?

谢谢!

【问题讨论】:

    标签: linux raspberry-pi streaming gstreamer alsa


    【解决方案1】:

    为了后代,我收到了来自GStreamer developer forum 的一个很好的提示。

    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 一起使用时不可避免的权衡?

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 2020-07-23
      • 1970-01-01
      • 2015-09-07
      • 2012-11-01
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多