コード例 #1
0
int main(int argc, char** argv)
{
    int ret = 0;
    
    // user options.
    char* in_flv_file;
    char* out_flv_file;
    // flv handler
    srs_flv_t ic = NULL;
    srs_flv_t oc = NULL;
    
    // temp variables.
    int tmp_file_size = 0;
    char* tmp_file;

    printf("inject flv file keyframes to metadata.\n");
    printf("srs(simple-rtmp-server) client librtmp library.\n");
    printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
    
    if (argc <= 2) {
        printf("inject flv file keyframes to metadata\n"
            "Usage: %s in_flv_file out_flv_file\n"
            "   in_flv_file         input flv file to inject.\n"
            "   out_flv_file        the inject output file, can be in_flv_file.\n"
            "For example:\n"
            "   %s doc/source.200kbps.768x320.flv injected.flv\n"
            "   %s ../../doc/source.200kbps.768x320.flv injected.flv\n",
            argv[0], argv[0], argv[0]);
        exit(-1);
    }
    
    in_flv_file = argv[1];
    out_flv_file = argv[2];
    
    tmp_file_size = strlen(out_flv_file) + strlen(".tmp") + 1;
    tmp_file = (char*)malloc(tmp_file_size);
    snprintf(tmp_file, tmp_file_size, "%s.tmp", out_flv_file);
    
    srs_human_trace("input:  %s", in_flv_file);
    srs_human_trace("output:  %s", out_flv_file);
    srs_human_trace("tmp_file:  %s", tmp_file);

    ret = process(in_flv_file, tmp_file, &ic, &oc);
    
    srs_flv_close(ic);
    srs_flv_close(oc);
    
    if (ret != 0) {
        unlink(tmp_file);
        if (ret == ERROR_INJECTED) {
            ret = 0;
            srs_human_trace("file already injected.");
        } else {
            srs_human_trace("error, remove tmp file.");
        }
    } else {
        rename(tmp_file, out_flv_file);
        srs_human_trace("completed, rename to %s", out_flv_file);
    }
    
    free(tmp_file);
    
    return ret;
}
コード例 #2
0
int main(int argc, char **argv) {
    int ret = 0;

    // main function
    tools_main_entrance_startup_time = srs_utils_time_ms();

    // user option parse index.
    int opt = 0;
    // user options.
    char *in_flv_file = NULL;
    char *out_rtmp_url = NULL;
    // rtmp handler
    srs_rtmp_t ortmp;
    // flv handler
    srs_flv_t flv;

    printf("ingest flv file and publish to RTMP server like FFMPEG.\n");
    printf("srs(simple-rtmp-server) client librtmp library.\n");
    printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());

    if (argc <= 2) {
        printf("ingest flv file and publish to RTMP server\n"
                       "Usage: %s <-i in_flv_file> <-y out_rtmp_url>\n"
                       "   in_flv_file     input flv file, ingest from this file.\n"
                       "   out_rtmp_url    output rtmp url, publish to this url.\n"
                       "For example:\n"
                       "   %s -i doc/source.200kbps.768x320.flv -y rtmp://127.0.0.1/live/livestream\n"
                       "   %s -i ../../doc/source.200kbps.768x320.flv -y rtmp://127.0.0.1/live/livestream\n",
               argv[0], argv[0], argv[0]);
        exit(-1);
    }

    for (opt = 0; opt < argc; opt++) {
        srs_human_trace("argv[%d]=%s", opt, argv[opt]);
    }

    // fill the options for mac
    for (opt = 0; opt < argc - 1; opt++) {
        // ignore all options except -i and -y.
        char *p = argv[opt];

        // only accept -x
        if (p[0] != '-' || p[1] == 0 || p[2] != 0) {
            continue;
        }

        // parse according the option name.
        switch (p[1]) {
            case 'i':
                in_flv_file = argv[opt + 1];
                break;
            case 'y':
                out_rtmp_url = argv[opt + 1];
                break;
            default:
                break;
        }
    }

    if (!in_flv_file) {
        srs_human_trace("input invalid, use -i <input>");
        return -1;
    }
    if (!out_rtmp_url) {
        srs_human_trace("output invalid, use -y <output>");
        return -1;
    }

    srs_human_trace("input:  %s", in_flv_file);
    srs_human_trace("output: %s", out_rtmp_url);

    if ((flv = srs_flv_open_read(in_flv_file)) == NULL) {
        ret = 2;
        srs_human_trace("open flv file failed. ret=%d", ret);
        return ret;
    }

    ortmp = srs_rtmp_create(out_rtmp_url);

    ret = proxy(flv, ortmp);
    srs_human_trace("ingest flv to RTMP completed");

    srs_rtmp_destroy(ortmp);
    srs_flv_close(flv);

    return ret;
}