wangrong
2025-01-23 02819b5c047bb354b0ef2374e7c6a6ac4bbd5bba
samples/from_argv_all_in_one_rtsp.cpp
@@ -36,31 +36,43 @@
    VP_LOGGER_INIT();
    std::vector<std::string> args(argv + 1, argv + argc);
    // 默认的命令行参数
    std::string rtsp_path = "rtsp://127.0.0.1:8554/demo";
    std::string kafka_server_point = "127.0.0.1:9092";
    float resize_ratio = 0.4;
    int skip_interval = 3;
    int channel_index = 21;
    bool usegpu = false; // 新增参数,默认值为 false
    // 如果提供了第一个和第二个参数,则覆盖默认的路径
    if (args.size() >= 5) {
    // 如果提供了至少 6 个参数,则覆盖默认值
    if (args.size() >= 6) {
        rtsp_path = args[0];
        resize_ratio = std::stof(args[1]);
        kafka_server_point = args[2];
        skip_interval = std::stoi(args[3]);
        channel_index = std::stoi(args[4]);
        std::string usegpu_arg = args[5];
        // 将字符串转换为布尔值,支持 true/false 或 1/0
        std::transform(usegpu_arg.begin(), usegpu_arg.end(), usegpu_arg.begin(), ::tolower);
        if (usegpu_arg == "true" || usegpu_arg == "1") {
            usegpu = true;
        } else if (usegpu_arg == "false" || usegpu_arg == "0") {
            usegpu = false;
        } else {
            std::cerr << "Invalid value for <usegpu>. Please use 'true', 'false', '1', or '0'.\n";
            return -1;
        }
    } else {
        std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point> <skip_interval>\n";
        std::cout << "Example: " << argv[0] << " rtsp://admin:Shmixcqwe%21%40%23@172.18.10.113/Streaming/Channels/101 0.4 172.18.0.247:9092 5 21 \n";
        std::cout << "Usage: " << argv[0] << " <rtsp_path> <resize_ratio> <kafka_server_point> <skip_interval> <channel_index> <usegpu>\n";
        std::cout << "Example: " << argv[0] << " rtsp://127.0.0.1:8554/demo 0.4 127.0.0.1:9092 5 21 true\n";
        return -1;
    }
    // create nodes
    //auto file_src_0 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_0", 0, rtsp_path, resize_ratio);
    //auto file_src_0 = std::make_shared<vp_nodes::vp_rtsp_src_node>("rtsp_src_1", 0, rtsp_path, resize_ratio, "avdec_h264", skip_interval); 
    auto file_src_0 = std::make_shared<vp_nodes::vp_rtsp_ffmpeg_src_node>("rtsp_src_1", channel_index, rtsp_path, resize_ratio, skip_interval);
    auto file_src_0 = std::make_shared<vp_nodes::vp_rtsp_ffmpeg_src_node>("rtsp_src_1", channel_index, rtsp_path, resize_ratio, skip_interval, usegpu);
    //auto file_src_1 = std::make_shared<vp_nodes::vp_file_src_node>("file_src_1", 1, "./vp_data/test_video/falldown.mp4", 0.5);
    //auto split = std::make_shared<vp_nodes::vp_split_node>("split", false, true);  // split by deep-copy not by channel!
    
@@ -74,8 +86,8 @@
    
    // define a region in frame for every channel (value MUST in the scope of frame'size)
    std::map<int, std::vector<vp_objects::vp_point>> regions = {
        {0, std::vector<vp_objects::vp_point>{vp_objects::vp_point(20, 30), vp_objects::vp_point(600, 40), vp_objects::vp_point(600, 300), vp_objects::vp_point(10, 300)}},  // channel0 -> region
        {1, std::vector<vp_objects::vp_point>{vp_objects::vp_point(20, 30), vp_objects::vp_point(1000, 40), vp_objects::vp_point(1000, 600), vp_objects::vp_point(10, 600)}}   // channel1 -> region
        {channel_index, std::vector<vp_objects::vp_point>{vp_objects::vp_point(290, 10), vp_objects::vp_point(340, 10), vp_objects::vp_point(600, 330), vp_objects::vp_point(40, 350)}},  // channel0 -> region
        {1, std::vector<vp_objects::vp_point>{vp_objects::vp_point(290, 10), vp_objects::vp_point(340, 10), vp_objects::vp_point(600, 330), vp_objects::vp_point(40, 350)}}   // channel1 -> region
    };
    auto ba_jam = std::make_shared<vp_nodes::vp_ba_jam_node>("ba_jam", regions);
    auto ba_stop = std::make_shared<vp_nodes::vp_ba_stop_node>("ba_stop", regions);