Revision 6d3d3b83 ffmpeg.c

View differences:

ffmpeg.c
1646 1646
    fflush(stdout);
1647 1647
}
1648 1648

  
1649
static int stream_index_from_inputs(AVFormatContext **input_files,
1650
                                    int nb_input_files,
1651
                                    AVInputFile *file_table,
1652
                                    AVInputStream **ist_table,
1653
                                    enum CodecType type,
1654
                                    int programid)
1655
{
1656
    int p, q, z;
1657
    for(z=0; z<nb_input_files; z++) {
1658
        AVFormatContext *ic = input_files[z];
1659
        for(p=0; p<ic->nb_programs; p++) {
1660
            AVProgram *program = ic->programs[p];
1661
            if(program->id != programid)
1662
                continue;
1663
            for(q=0; q<program->nb_stream_indexes; q++) {
1664
                int sidx = program->stream_index[q];
1665
                int ris = file_table[z].ist_index + sidx;
1666
                if(ist_table[ris]->discard && ic->streams[sidx]->codec->codec_type == type)
1667
                    return ris;
1668
            }
1669
        }
1670
    }
1671

  
1672
    return -1;
1673
}
1674

  
1675 1649
/*
1676 1650
 * The following code is the main loop of the file converter
1677 1651
 */
......
1803 1777
                }
1804 1778

  
1805 1779
            } else {
1806
                if(opt_programid) {
1807
                    found = 0;
1808
                    j = stream_index_from_inputs(input_files, nb_input_files, file_table, ist_table, ost->st->codec->codec_type, opt_programid);
1809
                    if(j != -1) {
1810
                        ost->source_index = j;
1811
                        found = 1;
1812
                    }
1813
                } else {
1814 1780
                    /* get corresponding input stream index : we select the first one with the right type */
1815 1781
                    found = 0;
1816 1782
                    for(j=0;j<nb_istreams;j++) {
1783
                        int skip=0;
1817 1784
                        ist = ist_table[j];
1818
                        if (ist->discard &&
1785
                        if(opt_programid){
1786
                            int pi,si;
1787
                            AVFormatContext *f= input_files[ ist->file_index ];
1788
                            skip=1;
1789
                            for(pi=0; pi<f->nb_programs; pi++){
1790
                                AVProgram *p= f->programs[pi];
1791
                                if(p->id == opt_programid)
1792
                                    for(si=0; si<p->nb_stream_indexes; si++){
1793
                                        if(f->streams[ p->stream_index[si] ] == ist->st)
1794
                                            skip=0;
1795
                                    }
1796
                            }
1797
                        }
1798
                        if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip &&
1819 1799
                            ist->st->codec->codec_type == ost->st->codec->codec_type) {
1820 1800
                            ost->source_index = j;
1821 1801
                            found = 1;
1822 1802
                            break;
1823 1803
                        }
1824 1804
                    }
1825
                }
1826 1805

  
1827 1806
                if (!found) {
1828 1807
                    if(! opt_programid) {
1829 1808
                        /* try again and reuse existing stream */
1830 1809
                        for(j=0;j<nb_istreams;j++) {
1831 1810
                            ist = ist_table[j];
1832
                            if (ist->st->codec->codec_type == ost->st->codec->codec_type) {
1811
                            if (   ist->st->codec->codec_type == ost->st->codec->codec_type
1812
                                && ist->st->discard != AVDISCARD_ALL) {
1833 1813
                                ost->source_index = j;
1834 1814
                                found = 1;
1835 1815
                            }
......
2909 2889
        av_exit(1);
2910 2890
    }
2911 2891
    if(opt_programid) {
2912
        int i;
2913
        for(i=0; i<ic->nb_programs; i++)
2914
            if(ic->programs[i]->id != opt_programid)
2915
                ic->programs[i]->discard = AVDISCARD_ALL;
2892
        int i, j;
2893
        int found=0;
2894
        for(i=0; i<ic->nb_streams; i++){
2895
            ic->streams[i]->discard= AVDISCARD_ALL;
2896
        }
2897
        for(i=0; i<ic->nb_programs; i++){
2898
            AVProgram *p= ic->programs[i];
2899
            if(p->id != opt_programid){
2900
                p->discard = AVDISCARD_ALL;
2901
            }else{
2902
                found=1;
2903
                for(j=0; j<p->nb_stream_indexes; j++){
2904
                    ic->streams[p->stream_index[j]]->discard= 0;
2905
                }
2906
            }
2907
        }
2908
        if(!found){
2909
            fprintf(stderr, "Specified program id not found\n");
2910
            av_exit(1);
2911
        }
2912
        opt_programid=0;
2916 2913
    }
2917 2914

  
2918 2915
    ic->loop_input = loop_input;

Also available in: Unified diff