VideoHelp Forum
+ Reply to Thread
Results 1 to 7 of 7
Thread
  1. Hi all,

    I would like to compile ffmpeg with fixed arguments, ie: ffmpeg -i rtsp://localhost/live -vcodec copy -acodec copy -f flv rtmp://remotehost/live

    I can't for security reasons call it from an external script, this must be included in the ffmpeg binary. Prblem is that the source codes are very big , so do u know a simple way to do that ?

    Tx
    Quote Quote  
  2. so do u know a simple way to do that ?
    overwrite "argc" and "argv" with the values you want at the beginning of the main in fftools/ffmpeg.c seems simple
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  3. hi,

    thanks for reply,

    I will do this.
    Quote Quote  
  4. i 've tried this, but the programm does not start with these fixed arguments (i do not have enough knowledges in C):

    int main(int argc, char **argv)
    {

    argv=malloc(10 * sizeof(char *));
    argv[1] =(char *) malloc( strlen("-i " ) + 1 );
    strcpy(argv[1],"-i " );
    argv[2] =(char *) malloc( strlen("rtsp://192.168.1.38/live " ) + 1 );
    strcpy(argv[2],"rtsp://192.168.1.38/axis-media/media.amp " );
    argv[3] =(char *) malloc( strlen("-vcodec " ) + 1 );
    strcpy(argv[3],"-vcodec " );
    argv[4] =(char *) malloc( strlen("copy " ) + 1 );
    strcpy(argv[4],"copy " );
    argv[5] =(char *) malloc( strlen("-acodec " ) + 1 );
    strcpy(argv[5],"-acodec " );
    argv[6] =(char *) malloc( strlen("copy " ) + 1 );
    strcpy(argv[6],"copy " );
    argv[7] =(char *) malloc( strlen("-f " ) + 1 );
    strcpy(argv[7],"-f " );
    argv[8] =(char *) malloc( strlen("flv " ) + 1 );
    strcpy(argv[8],"flv " );
    argv[9] =(char *) malloc( strlen("rtmp://192.168.1.114/live " ) + 1 );
    strcpy(argv[9],"rtmp://192.168.1.114/hls/axis " );
    printf("argument %s\n", argv[1]);
    printf("argument %s\n", argv[2]);
    printf("argument %s\n", argv[3]);
    printf("argument %s\n", argv[4]);
    printf("argument %s\n", argv[5]);
    printf("argument %s\n", argv[6]);
    printf("argument %s\n", argv[7]);
    printf("argument %s\n", argv[8]);
    printf("argument %s\n", argv[9]);

    argv[10]=NULL;
    /*for (i=0; i < 9; i++)*/
    free(argv);
    return 0;
    }
    Quote Quote  
  5. argv[2] =(char *) malloc( strlen("rtsp://192.168.1.38/live " ) + 1 );

    argv[9] =(char *) malloc( strlen("rtmp://192.168.1.114/live " ) + 1 );
    ^^^This is never going to work, malloc is used to allocate memory, and in this case is being used with strlen which gets the length of a string argument, that argument can either be a variable or a constant. Your modification is a variable but you haven't defined the variable anywhere, in other words you are attempting to treat an undefined variable as a constant.

    I won't even begin to dissect everything else wrong with your approach.

    As for Selur's "overwrite "argc" and "argv" with the values you want at the beginning of the main in fftools/ffmpeg.c seems simple", I would take anything he tells you about programming with some salt, and possibly some pepper also; if you have ever used that buggy mess of a program he created, Hybrid, you would know that he is not the bastion of competent programming.
    Quote Quote  
  6. @netlink1987: haven't written C code for ages, but I guess it should be something more like:
    Code:
    char* name = argv[0]; // grab first argument from original argv
    // overwrite existing 
    *argv[] = {
      name, // 0
      '-i', // 1
      'rtsp://192.168.1.38/axis-media/media.am', //2
      '-vcodec', // 3
      'copy', // 4
      '-acodec', //5
      'copy', // 6
      '-f', // 7
      'flv', //8
      'rtmp://192.168.1.114/hls/axis', // 9
    };
    argc = 10; // argument count
    the main function in ffmpeg,c starts with:
    Code:
    int main(int argc, char **argv)
    {
        int i, ret;
        BenchmarkTimeStamps ti;
    
        init_dynload();
    inserting the above code between 'BenchmarkTimeStamps ti;' and 'init_dynload();' should overwrite arc and argv.

    @sophiscticles: my condolences, being you must suck
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  7. Here's a correction to C / C++11 syntax (not sure which ffmpeg uses atm.)
    Code:
    argc = 10; // argument count
    argv = new char *[argc];
    argv[0] = name;
    argv[1] = "-i";
    argv[2] = "rtsp://192.168.1.38/axis-media/media.am";
    argv[3] = "-vcodec";
    argv[4] = "copy";
    argv[5] = "-acodec";
    argv[6] = "copy";
    argv[7] = "-f";
    argv[8] = "flv";
    argv[9] = "rtmp://192.168.1.114/hls/axis";
    in case ffmpeg does use c++11, you will have to use something like:
    Code:
    char* name = argv[0]; // grab first argument from original argv
      // overwrite existing
      argc = 10; // argument count
      argv = new char *[argc];
      argv[0] = name;
      char tmp1[] = "-i";
      strcpy_s(tmp1, argv[1]);
      char tmp2[] = "rtsp://192.168.1.38/axis-media/media.am";
      strcpy_s(tmp2, argv[2]);
      char tmp3[] = "-vcodec";
      strcpy_s(tmp3, argv[3]);
      char tmp4[] = "copy";
      strcpy_s(tmp4, argv[4]);
      char tmp5[] = "-acodec";
      strcpy_s(tmp5, argv[5]);
      char tmp6[] = "copy";
      strcpy_s(tmp6, argv[6]);
      char tmp7[] = "-f";
      strcpy_s(tmp7, argv[7]);
      char tmp8[] = "flv";
      strcpy_s(tmp8, argv[8]);
      char tmp9[] = "rtmp://192.168.1.114/hls/axis";
      strcpy_s(tmp9, argv[9]);
    Cu Selur
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!