[linux]视频实时推流项目


当前文档描述基于3.加入Buildroot自动构建

Makefile文件:

上面是临时代码编辑区
实际代码位于:toppet@ubuntu:~/Documents/linuxsrc/rk3568_linux_5.10/buildroot/package/rov-streamer$

Config.in:

添加"rov-streamer"选项

按空格勾选[rov-streamer]
rov_streamer.c:

#include <gst/gst.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
    GstElement *pipeline;
    GstBus *bus;
    GstMessage *msg;

    /* 1. 初始化 GStreamer */
    gst_init(&argc, &argv);

    /* 2. 构建推流管道字符串 (使用你测试成功的 RTP 逻辑) */
    /* 注意:代码中的双引号需要转义,末尾无需反斜杠 */
//   const char *pipe_str = 
 //      "v4l2src device=/dev/video9 ! "
  //     "image/jpeg,width=640,height=480,framerate=30/1 ! "
   //     "jpegdec ! videoconvert ! video/x-raw,format=NV12 ! "
    //    "mpph264enc bps=2000000 gop=10 ! "
     //   "rtph264pay config-interval=1 ! "
      //  "udpsink host=192.168.1.89 port=5678 sync=false";
const char *pipe_str =
        "v4l2src device=/dev/video9 ! "
        "video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! "
        "videoconvert ! video/x-raw,format=NV12 ! "
        "mpph264enc bps=2000000 gop=30 profile=66 ! "
        "rtph264pay config-interval=1 ! "
        "udpsink host=192.168.1.89 port=5678 sync=false";

    printf("正在启动 ROV 视频流...\n");

    /* 3. 创建管道 */
    pipeline = gst_parse_launch(pipe_str, NULL);

    /* 4. 开始播放 */
    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    /* 5. 等待错误或流结束 (或者你可以自己写循环控制) */
    bus = gst_element_get_bus(pipeline);
    msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
                                     GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    /* 6. 释放资源 */
    if (msg != NULL)
        gst_message_unref(msg);
    gst_object_unref(bus);
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(pipeline);

    return 0;
                                                          

rov_streamer.mk:

################################################################################
#
# rov-streamer
#
################################################################################

ROV_STREAMER_VERSION = 1.0
# 告诉 Buildroot 源码就在本地路径
# 替换为你实际的绝对路径
ROV_STREAMER_SITE = /home/toppet/Documents/linuxsrc/rk3568_linux_5.10/buildroot/package/rov-streamer/src
ROV_STREAMER_SITE_METHOD = local

# 编译时需要的依赖库
ROV_STREAMER_DEPENDENCIES = gstreamer1 gst1-plugins-base

define ROV_STREAMER_BUILD_CMDS
        $(TARGET_CC) $(TARGET_CFLAGS) $(@D)/rov_streamer.c -o $(@D)/rov_streamer \
                $(TARGET_LDFLAGS) `$(PKG_CONFIG_HOST_BINARY) --cflags --libs gstreamer-1.0`
endef



# --- 必须添加下面这段,否则板子里找不到程序 ---
define ROV_STREAMER_INSTALL_TARGET_CMDS
        $(INSTALL) -D -m 0755 $(@D)/rov_streamer $(TARGET_DIR)/usr/bin/rov_streamer
endef

define ROV_STREAMER_INSTALL_INIT_SYSTEMD
    # 将 service 文件拷贝到系统的服务目录
    $(INSTALL) -D -m 0644 $(@D)/rov_streamer.service \
        $(TARGET_DIR)/usr/lib/systemd/system/rov_streamer.service
    
    # 创建软链接,确保服务默认是开启(enable)状态
    mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
    ln -fs ../../../../usr/lib/systemd/system/rov_streamer.service \
        $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/rov_streamer.service
endef



当修改完成rov-streamer.c以后,
执行:

编译修改以后的rov_streamer.c
完成以后,执行make,生成镜像


生成镜像里面rootfs.ext2用于RKDevtool烧录
文件拷贝到共享文件夹里面:

使用RKDev进行烧录:


文件send到板子
使用scp
Mob上面Serial敲入:
root@topeet:/# /etc/init.d/S50sshd start
Starting sshd: OK
用于启动ssh

Buildroot软件包配置:

rov_streamer.c代码:
 

#include <gst/gst.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
    GstElement *pipeline;
    GstBus *bus;
    GstMessage *msg;

    /* 1. 初始化 GStreamer */
    gst_init(&argc, &argv);

    /* 2. 构建推流管道字符串 (使用你测试成功的 RTP 逻辑) */
    /* 注意:代码中的双引号需要转义,末尾无需反斜杠 */
    const char *pipe_str = 
        "v4l2src device=/dev/video9 ! "
        "image/jpeg,width=640,height=480,framerate=30/1 ! "
        "jpegdec ! videoconvert ! video/x-raw,format=NV12 ! "
        "mpph264enc bps=2000000 gop=10 ! "
        "rtph264pay config-interval=1 ! "
        "udpsink host=192.168.1.89 port=5678 sync=false";

    printf("正在启动 ROV 视频流...\n");

    /* 3. 创建管道 */
    pipeline = gst_parse_launch(pipe_str, NULL);

    /* 4. 开始播放 */
    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    /* 5. 等待错误或流结束 (或者你可以自己写循环控制) */
    bus = gst_element_get_bus(pipeline);
    msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
                                     GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    /* 6. 释放资源 */
    if (msg != NULL)
        gst_message_unref(msg);
    gst_object_unref(bus);
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(pipeline);

    return 0;
}

视频流架构是:[摄像头] -> [V4L2 驱动] -> [GStreamer (MPP 硬件编码)] -> [RTP over UDP] -> [Windows 以太网] -> [SDP 解析] -> [FFmpeg/ffplay 解码显示]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值