opencv - 将多个 RTSP 流记录到一个文件中

标签 opencv ffmpeg vlc rtsp openrtsp

我需要将 4 个 RTSP 流记录到一个文件中。

流必须以这种方式放入视频中:

 ---------- ---------- 
|          |          |
| STREAM 1 | STREAM 2 |
|          |          |
|----------|----------|
|          |          |
| STREAM 3 | STREAM 4 |
|          |          |
 ---------- ----------

我需要以大约 1 秒的精度同步这些实时流。这是具有挑战性的,因为流具有可变帧率 (FPS)。

我试过ffmpeg但流不同步。
这是代码:
ffmpeg \
  -i "rtsp://IP-ADDRESS/cam/realmonitor?channel=1&subtype=00" \
  -i "rtsp://IP-ADDRESS/live?real_stream" \
  -i "rtsp://IP-ADDRESS/live?real_stream" \
  -i "rtsp://IP-ADDRESS/live?real_stream" \
  -filter_complex " \
    nullsrc=size=1920x1080 [base]; \
    [0:v] scale=960x540 [video0]; \
    [1:v] scale=960x540 [video1]; \
    [2:v] scale=960x540 [video2]; \
    [3:v] scale=960x540 [video3]; \
    [base][video0] overlay=shortest=1:x=0:y=0 [tmp1]; \
    [tmp1][video1] overlay=shortest=0:x=960:y=0 [tmp2]; \
    [tmp2][video2] overlay=shortest=0:x=0:y=540 [tmp3]; \
    [tmp3][video3] overlay=shortest=0:x=960:y=540 [v]; \
    [0:a]amix=inputs=1[a]" \
  -map "[v]" -map "[a]" -c:v h264 videos/test-combine-cams.mp4

有没有办法在 ffmpeg 中组合和同步流?或使用其他实用程序,例如:vlc , openRTSP , OpenCV ?

最佳答案

您是否尝试过 gstreamer,它适用于我的 rtsp 流。

gst-launch-1.0 -e rtspsrc location=rtsp_url1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! m.sink_0 \
               rtspsrc location=rtsp_url2 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! m.sink_1 \
               rtspsrc location=rtsp_url3 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! m.sink_2 \
               rtspsrc location=rtsp_url4 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! m.sink_3 \
               videomixer name=m sink_1::xpos=1280 sink_2::ypos=720 sink_3::xpos=1280 sink_3::ypos=720 ! x264enc ! mp4mux ! filesink location=./out.mp4 sync=true

当然,您需要添加您的 rtsp url 并根据您的视频大小(我的是 720p)调整 videomixer xpos/ypos 属性。

在混合之前,您可能希望一次只运行一个,以确保您正确安装了所有依赖项
gst-launch-1.0 rtspsrc location=rtsp_url1 ! rtph264depay ! h264parse ! decodebin ! x264enc ! mp4mux ! filesink location=./out.mp4 sync=true
我还没有添加音频。

关于opencv - 将多个 RTSP 流记录到一个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59320085/

相关文章:

video - 使用 ffmpeg 解码基本 HEVC 流

encryption - 是否可以将 CSA 解密与 FFMPEG 一起使用?

python - 如何使用python和openCV制作热图

python - 将 “libpython2.7.a”版本从2.7.5更改为2.7.6以安装opencv 2.4.9

c++ - 快速算法 : No Corner Detection in Rectangular shapes

ffmpeg - 运行时错误 : No ffmpeg exe could be found - FFMpeg error in Windows 10

audio - 将音视频与 ffmpeg 合并时如何提高生成视频的质量?

c++ - DVB PSI解码

android - 如何通过基于 VLC 或 RTSP 的 WiFi 从 Android 发送流媒体?

c++ - 针对 C++ 类型测试 opencv mat 数据类型的最佳方法是什么?