Revision b25d931a ffmpeg.c

View differences:

ffmpeg.c
1948 1948
                     int nb_input_files,
1949 1949
                     AVStreamMap *stream_maps, int nb_stream_maps)
1950 1950
{
1951
    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
1951
    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0, step;
1952 1952
    AVFormatContext *is, *os;
1953 1953
    AVCodecContext *codec, *icodec;
1954 1954
    AVOutputStream *ost, **ost_table = NULL;
......
1959 1959
    int want_sdp = 1;
1960 1960
    uint8_t no_packet[MAX_FILES]={0};
1961 1961
    int no_packet_count=0;
1962
    int nb_frame_threshold[AVMEDIA_TYPE_NB]={0};
1963
    int nb_streams[AVMEDIA_TYPE_NB]={0};
1962 1964

  
1963 1965
    file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
1964 1966
    if (!file_table)
......
2043 2045
    ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
2044 2046
    if (!ost_table)
2045 2047
        goto fail;
2048

  
2049
    for(k=0;k<nb_output_files;k++) {
2050
        os = output_files[k];
2051
        for(i=0;i<os->nb_streams;i++,n++) {
2052
            nb_streams[os->streams[i]->codec->codec_type]++;
2053
        }
2054
    }
2055
    for(step=1<<30; step; step>>=1){
2056
        int found_streams[AVMEDIA_TYPE_NB]={0};
2057
        for(j=0; j<AVMEDIA_TYPE_NB; j++)
2058
            nb_frame_threshold[j] += step;
2059

  
2060
        for(j=0; j<nb_istreams; j++) {
2061
            int skip=0;
2062
            ist = ist_table[j];
2063
            if(opt_programid){
2064
                int pi,si;
2065
                AVFormatContext *f= input_files[ ist->file_index ];
2066
                skip=1;
2067
                for(pi=0; pi<f->nb_programs; pi++){
2068
                    AVProgram *p= f->programs[pi];
2069
                    if(p->id == opt_programid)
2070
                        for(si=0; si<p->nb_stream_indexes; si++){
2071
                            if(f->streams[ p->stream_index[si] ] == ist->st)
2072
                                skip=0;
2073
                        }
2074
                }
2075
            }
2076
            if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip
2077
                && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){
2078
                found_streams[ist->st->codec->codec_type]++;
2079
            }
2080
        }
2081
        for(j=0; j<AVMEDIA_TYPE_NB; j++)
2082
            if(found_streams[j] < nb_streams[j])
2083
                nb_frame_threshold[j] -= step;
2084
    }
2046 2085
    n = 0;
2047 2086
    for(k=0;k<nb_output_files;k++) {
2048 2087
        os = output_files[k];
......
2065 2104
                }
2066 2105

  
2067 2106
            } else {
2068
                int best_nb_frames=-1;
2069 2107
                /* get corresponding input stream index : we select the first one with the right type */
2070 2108
                found = 0;
2071 2109
                for(j=0;j<nb_istreams;j++) {
......
2085 2123
                        }
2086 2124
                    }
2087 2125
                    if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip &&
2088
                        ist->st->codec->codec_type == ost->st->codec->codec_type) {
2089
                        if(best_nb_frames < ist->st->codec_info_nb_frames){
2090
                            best_nb_frames= ist->st->codec_info_nb_frames;
2126
                        ist->st->codec->codec_type == ost->st->codec->codec_type &&
2127
                        nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames) {
2091 2128
                            ost->source_index = j;
2092 2129
                            found = 1;
2093
                        }
2130
                            break;
2094 2131
                    }
2095 2132
                }
2096 2133

  

Also available in: Unified diff