raspberry-pi - 如何使用 Gstreamer 将实时音频和视频混合到 mpegts?
问题描述
目标:
在 Raspberry Pi 上,从连接的摄像头和麦克风获取输入,合并为单个流,使用 VLC 应用程序跨网络播放。
更多详细信息:
我正在尝试使用 Raspberry Pi Zero W、USB 麦克风和通过 Pi 的摄像头端口连接的摄像头来制作相当于 IP 摄像头的东西。这个想法是让实时音频和视频只能在我的本地网络上从任何可以运行 VLC 播放器的设备上查看。
视频正在运行
我决定使用 Gstreamer 的命令行工具来构建这个应用程序,因为据报道它的延迟比使用类似cvlc
或ffmpeg
. 根据此链接中的代码,我构建了一个仅可工作的视频管道。
#!/bin/bash
dstAdr=${1:-192.168.0.255}
raspivid -n -w 640 -h 480 -fps 20 -b 2000000 -a 12 -t 0 -o - \
| gst-launch-1.0 -v fdsrc \
! video/x-h264, width=640, height=480, framerate=20/1 \
! h264parse config-interval=-1 \
! mpegtsmux \
! udpsink host=$dstAdr port=5004
udp://@:5004
通过在 VLC 中打开网络流,可以从我的 PC 和智能手机查看此流。
如何包含音频?
我有一个 USB 麦克风,我希望用它来捕获实时音频并将其包含在 MPEG 流中。我通过录制一段短片并在我的电脑上播放文件来确认麦克风可以正常工作。
根据此答案中对 Gstreamer muxes 的描述,我创建了以下管道以尝试将音频包含在流中:
raspivid -n -w 640 -h 480 -fps 20 -b 2000000 -a 12 -t 0 -o - \
| gst-launch-1.0 -e -v fdsrc \
! video/x-h264, width=640, height=480, framerate=20/1 \
! h264parse config-interval=-1 \
! mpegtsmux name=mux \
! rtpmp2tpay \
! udpsink host=$dstAdr port=5004 \
alsasrc device=hw:1,0 \
! audio/x-raw, channels=1, rate=44100 \
! queue \
! lamemp3enc \
! mux.
麦克风只有1个通道,而且速率也经过了双重检查。管道不会立即抛出错误消息,但其他设备上的 VLC 无法播放流。一段时间后,将显示此错误消息:
ERROR: from element /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0:
streaming stopped, reason not-negotiated (-4)
EOS on shutdown enabled -- waiting for EOS after Error
Waiting for EOS...
ERROR: from element /GstPipeline:pipeline0/GstQueue:queue0: Internal data stream error.
Additional debug info:
gstqueue.c(988): gst_queue_handle_sink_event (): /GstPipeline:pipeline0/GstQueue:queue0:
streaming stopped, reason not-negotiated (-4)
问题
- 是否需要明确包含其他选项
alsasrc
? - 甚至可以使用 Gstreamer 命令行工具将两个实时提要混合到一个流中吗?
- 是否可以使用 Gstreamer C API 做到这一点?
解决方案
推荐阅读
- angular - 类型'可观察的
' 不可分配给类型 'Entity[]' - apache-spark - Jupyter Notebook 连接到远程配置单元
- css - 如何在 HTML 中强制分词?
- php - 通过从 mysqli 表中获取最后一条记录 id 来增加 ID
- python - Python 请求无法正常工作
- serilog - Serilog 无法显示输出日志 aspnetcore 2.1 vs 2017
- javascript - 如何解决 Mozilla Firefox 和 IE 中的 NaN:NaN:NaN 错误
- python - 为 Google ML Engine 部署减少 Tensorflow SavedModel 的大小
- ios - 在swift 3中使用SWreveal视图控制器从搜索页面导航回主页时导航栏消失?
- angular - mockbackend/XHRBackend 测试的 Angular 5 问题