Linux系统下使用C++推流多路视频流

先看拉取的视频流效果:

image-20240310084051649

代码如下:

一开始打算使用python写多路视频推流,但在ubuntu系统上搞了好久就是搞不定openh264导致的错误,然后改用c++了,代码如下,我这里推了两路视频流,一路是网络摄像头,另一路是MP4视频文件,环境还是之前的,可参考以下两篇博文:

Docker中创建nginx-rtmp流媒体服务器
Docker中使用nginx-rtmp推拉网络摄像头视频流


#include <iostream>
#include <thread>

void executeCommand(const char* command) {
    int result = std::system(command);

    if (result == 0) {
        std::cout << "Command executed successfully." << std::endl;
    } else {
        std::cerr << "Command execution failed." << std::endl;
    }
}

int main() {
    // 构建推流命令
    const char* command1 = "ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://admin:admin@网络摄象头ip -c:v h264 -b:v 1000k -c:a aac -ar 44100 -f flv rtmp://流媒体服务器IP:1935/stream/example1";

    // 构建另一个推流命令
    const char* command2 = "ffmpeg -re -stream_loop -1 -i ./5-2.mp4 -vcodec copy -acodec aac -ar 44100 -f flv rtmp://流媒体服务器IP:1935/stream/example2";

    // 使用线程同时执行两个命令
    std::thread thread1(executeCommand, command1);
    std::thread thread2(executeCommand, command2);

    // 等待线程执行完毕
    thread1.join();
    thread2.join();

    return 0;
}


编译命令:

g++ -o multffmpeg-test multffmpeg-test.cpp -pthread

运行:

./multffmpeg-test

相关推荐

  1. Linux环境使用flv.js + websokect播放RTSP视频

    2024-03-15 01:14:01       61 阅读
  2. c# 视频压缩

    2024-03-15 01:14:01       60 阅读
  3. ubuntu利用ffmpeg工具将视频至rtsp

    2024-03-15 01:14:01       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-15 01:14:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-15 01:14:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-15 01:14:01       82 阅读
  4. Python语言-面向对象

    2024-03-15 01:14:01       91 阅读

热门阅读

  1. 新手如何学习Kubernetes【入门篇】

    2024-03-15 01:14:01       46 阅读
  2. 模块化(理解)

    2024-03-15 01:14:01       37 阅读
  3. 深入理解 MySQL 中的 CASE 语句:从基础到实战

    2024-03-15 01:14:01       39 阅读
  4. 配置 conda为国内源

    2024-03-15 01:14:01       42 阅读
  5. git 批量clone,pull 项目

    2024-03-15 01:14:01       43 阅读
  6. python--运算符和字符串

    2024-03-15 01:14:01       45 阅读
  7. SpringBoot如何修改pom依赖的默认版本号

    2024-03-15 01:14:01       44 阅读
  8. vue3中子级页面绑定调用父级页面得自定义事件

    2024-03-15 01:14:01       41 阅读
  9. 力扣爆刷第95天之hot100五连刷61-65

    2024-03-15 01:14:01       40 阅读
  10. sql语句

    2024-03-15 01:14:01       41 阅读