Skip to content
Snippets Groups Projects
ffmpeg.c 63 KiB
Newer Older
  • Learn to ignore specific revisions
  • Fabrice Bellard's avatar
    Fabrice Bellard committed
        /* video options */
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        { "b", HAS_ARG, {(void*)opt_video_bitrate}, "set video bitrate (in kbit/s)", "bitrate" },
        { "r", HAS_ARG, {(void*)opt_frame_rate}, "set frame rate (in Hz)", "rate" },
        { "s", HAS_ARG, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
        { "g", HAS_ARG | OPT_EXPERT, {(void*)opt_gop_size}, "set the group of picture size", "gop_size" },
        { "intra", OPT_BOOL | OPT_EXPERT, {(void*)&intra_only}, "use only intra frames"},
        { "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" },
        { "qscale", HAS_ARG | OPT_EXPERT, {(void*)opt_qscale}, "use fixed video quantiser scale (VBR)", "q" },
    
        { "qmin", HAS_ARG | OPT_EXPERT, {(void*)opt_qmin}, "min video quantiser scale (VBR)", "q" },
        { "qmax", HAS_ARG | OPT_EXPERT, {(void*)opt_qmax}, "max video quantiser scale (VBR)", "q" },
        { "qdiff", HAS_ARG | OPT_EXPERT, {(void*)opt_qdiff}, "max difference between the quantiser scale (VBR)", "q" },
        { "qblur", HAS_ARG | OPT_EXPERT, {(void*)opt_qblur}, "video quantiser scale blur (VBR)", "blur" },
        { "qcomp", HAS_ARG | OPT_EXPERT, {(void*)opt_qcomp}, "video quantiser scale compression (VBR)", "compression" },
        { "bt", HAS_ARG, {(void*)opt_video_bitrate_tolerance}, "set video bitrate tolerance (in kbit/s)", "tolerance" },
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    #ifdef CONFIG_GRAB
        { "vd", HAS_ARG | OPT_EXPERT, {(void*)opt_video_device}, "set video device", "device" },
    #endif
        { "vcodec", HAS_ARG | OPT_EXPERT, {(void*)opt_video_codec}, "force video codec", "codec" },
        { "me", HAS_ARG | OPT_EXPERT, {(void*)opt_motion_estimation}, "set motion estimation method", 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
          "method" },
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        { "sameq", OPT_BOOL, {(void*)&same_quality}, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
          "use same video quality as source (implies VBR)" },
        /* audio options */
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        { "ab", HAS_ARG, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", },
        { "ar", HAS_ARG, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
        { "ac", HAS_ARG, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
        { "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" },
    #ifdef CONFIG_GRAB
        { "ad", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_device}, "set audio device", "device" },
    #endif
        { "acodec", HAS_ARG | OPT_EXPERT, {(void*)opt_audio_codec}, "force audio codec", "codec" },
        { "deinterlace", OPT_BOOL | OPT_EXPERT, {(void*)&do_deinterlace}, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark}, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
          "add timings for benchmarking" },
    
        { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump}, 
          "dump each input packet" },
    
        { "psnr", OPT_BOOL | OPT_EXPERT, {(void*)&do_psnr}, "calculate PSNR of compressed frames" }, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
        { NULL, },
    };
    
    int main(int argc, char **argv)
    {
        int optindex, i;
        const char *opt, *arg;
        const OptionDef *po;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        
        register_all();
    
    
        /* detect if invoked as player */
        i = strlen(argv[0]);
        if (i >= 6 && !strcmp(argv[0] + i - 6, "ffplay"))
            do_play = 1;
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        if (argc <= 1)
            show_help();
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        optindex = 1;
        while (optindex < argc) {
            opt = argv[optindex++];
            
            if (opt[0] == '-' && opt[1] != '\0') {
                po = options;
                while (po->name != NULL) {
                    if (!strcmp(opt + 1, po->name))
                        break;
                    po++;
                }
                if (!po->name) {
                    fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
                    exit(1);
                }
                arg = NULL;
                if (po->flags & HAS_ARG)
                    arg = argv[optindex++];
                if (po->flags & OPT_STRING) {
                    char *str;
                    str = strdup(arg);
                    *po->u.str_arg = str;
                } else if (po->flags & OPT_BOOL) {
                    *po->u.int_arg = 1;
                } else {
                    po->u.func_arg(arg);
                }
            } else {
    
                if (!do_play) {
                    opt_output_file(opt);
                } else {
                    opt_input_file(opt);
                }
    
        if (!do_play) {
            /* file converter / grab */
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            if (nb_output_files <= 0) {
                fprintf(stderr, "Must supply at least one output file\n");
                exit(1);
            }
    
        } else {
            /* player */
            if (nb_input_files <= 0) {
                fprintf(stderr, "Must supply at least one input file\n");
                exit(1);
            }
            prepare_play();
        }
    
        ti = getutime();
        av_encode(output_files, nb_output_files, input_files, nb_input_files, 
                  stream_maps, nb_stream_maps);
        ti = getutime() - ti;
        if (do_benchmark) {
            printf("bench: utime=%0.3fs\n", ti / 1000000.0);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        }
    
        /* close files */
        for(i=0;i<nb_output_files;i++) {
            if (!(output_files[i]->format->flags & AVFMT_NOFILE)) 
                url_fclose(&output_files[i]->pb);
        }
        for(i=0;i<nb_input_files;i++) {
            if (!(input_files[i]->format->flags & AVFMT_NOFILE)) 
                url_fclose(&input_files[i]->pb);
        }
    
        return 0;
    }