Skip to content
Snippets Groups Projects
ffmpeg.c 149 KiB
Newer Older
  • Learn to ignore specific revisions
  •             process_input_packet(ist, NULL);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    
        /* write the trailer if needed and close file */
    
    Aneesh Dogra's avatar
    Aneesh Dogra committed
        for (i = 0; i < nb_output_files; i++) {
    
            av_write_trailer(os);
    
        /* dump report by using the first video and audio streams */
    
        print_report(1, timer_start, av_gettime_relative());
    
        /* close each encoder */
    
        for (i = 0; i < nb_output_streams; i++) {
    
            if (ost->encoding_needed) {
    
                av_freep(&ost->enc_ctx->stats_in);
    
        /* close each decoder */
        for (i = 0; i < nb_input_streams; i++) {
    
            if (ist->decoding_needed) {
    
                avcodec_close(ist->dec_ctx);
    
                if (ist->hwaccel_uninit)
    
                    ist->hwaccel_uninit(ist->dec_ctx);
    
    #if HAVE_PTHREADS
    
        free_input_threads();
    #endif
    
        if (output_streams) {
            for (i = 0; i < nb_output_streams; i++) {
    
                if (ost) {
                    if (ost->logfile) {
                        fclose(ost->logfile);
                        ost->logfile = NULL;
    
                    av_freep(&ost->forced_kf_pts);
    
                    av_dict_free(&ost->encoder_opts);
    
                    av_dict_free(&ost->resample_opts);
    
                    av_dict_free(&ost->bsf_args);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    }
    
    
    static int64_t getutime(void)
    
    #if HAVE_GETRUSAGE
        struct rusage rusage;
    
        getrusage(RUSAGE_SELF, &rusage);
        return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec;
    #elif HAVE_GETPROCESSTIMES
        HANDLE proc;
        FILETIME c, e, k, u;
        proc = GetCurrentProcess();
        GetProcessTimes(proc, &c, &e, &k, &u);
        return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10;
    #else
    
        return av_gettime_relative();
    
    static int64_t getmaxrss(void)
    {
    #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
        struct rusage rusage;
        getrusage(RUSAGE_SELF, &rusage);
        return (int64_t)rusage.ru_maxrss * 1024;
    #elif HAVE_GETPROCESSMEMORYINFO
        HANDLE proc;
        PROCESS_MEMORY_COUNTERS memcounters;
        proc = GetCurrentProcess();
        memcounters.cb = sizeof(memcounters);
        GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters));
        return memcounters.PeakPagefileUsage;
    #else
        return 0;
    #endif
    }
    
    
    static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
    
    int main(int argc, char **argv)
    {
    
        int ret;
    
        register_exit(ffmpeg_cleanup);
    
        setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
    
    
        av_log_set_flags(AV_LOG_SKIP_REPEATED);
    
        parse_loglevel(argc, argv, options);
    
        if(argc>1 && !strcmp(argv[1], "-d")){
    
            av_log_set_callback(log_callback_null);
            argc--;
            argv++;
        }
    
    
    Luca Abeni's avatar
    Luca Abeni committed
        avcodec_register_all();
    
    Luca Abeni's avatar
    Luca Abeni committed
        avdevice_register_all();
    
    #endif
        avfilter_register_all();
    
        av_register_all();
    
        avformat_network_init();
    
        show_banner(argc, argv, options);
    
        /* parse options and open all input/output files */
    
        ret = ffmpeg_parse_options(argc, argv);
    
        if (ret < 0)
    
            exit_program(1);
    
        if (nb_output_files <= 0 && nb_input_files == 0) {
    
            av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
    
            exit_program(1);
    
        /* file converter / grab */
        if (nb_output_files <= 0) {
    
            av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
    
            exit_program(1);
    
    //     if (nb_input_files == 0) {
    //         av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
    
        current_time = ti = getutime();
    
            exit_program(1);
    
        ti = getutime() - ti;
        if (do_benchmark) {
    
            av_log(NULL, AV_LOG_INFO, "bench: utime=%0.3fs\n", ti / 1000000.0);
    
        av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, %"PRIu64" decoding errors\n",
               decode_error_stat[0], decode_error_stat[1]);
    
        if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
    
            exit_program(69);
    
        exit_program(received_nb_signals ? 255 : main_return_code);
        return main_return_code;