Originally committed as revision 21999 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2010/02/24 00:08:41... | ... |
@@ -1646,32 +1646,6 @@ static void print_sdp(AVFormatContext **avc, int n) |
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,33 +1777,39 @@ static int av_encode(AVFormatContext **output_files, |
1803 | 1803 |
} |
1804 | 1804 |
|
1805 | 1805 |
} 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 | 1806 |
/* get corresponding input stream index : we select the first one with the right type */ |
1815 | 1807 |
found = 0; |
1816 | 1808 |
for(j=0;j<nb_istreams;j++) { |
1809 |
+ int skip=0; |
|
1817 | 1810 |
ist = ist_table[j]; |
1818 |
- if (ist->discard && |
|
1811 |
+ if(opt_programid){ |
|
1812 |
+ int pi,si; |
|
1813 |
+ AVFormatContext *f= input_files[ ist->file_index ]; |
|
1814 |
+ skip=1; |
|
1815 |
+ for(pi=0; pi<f->nb_programs; pi++){ |
|
1816 |
+ AVProgram *p= f->programs[pi]; |
|
1817 |
+ if(p->id == opt_programid) |
|
1818 |
+ for(si=0; si<p->nb_stream_indexes; si++){ |
|
1819 |
+ if(f->streams[ p->stream_index[si] ] == ist->st) |
|
1820 |
+ skip=0; |
|
1821 |
+ } |
|
1822 |
+ } |
|
1823 |
+ } |
|
1824 |
+ if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && |
|
1819 | 1825 |
ist->st->codec->codec_type == ost->st->codec->codec_type) { |
1820 | 1826 |
ost->source_index = j; |
1821 | 1827 |
found = 1; |
1822 | 1828 |
break; |
1823 | 1829 |
} |
1824 | 1830 |
} |
1825 |
- } |
|
1826 | 1831 |
|
1827 | 1832 |
if (!found) { |
1828 | 1833 |
if(! opt_programid) { |
1829 | 1834 |
/* try again and reuse existing stream */ |
1830 | 1835 |
for(j=0;j<nb_istreams;j++) { |
1831 | 1836 |
ist = ist_table[j]; |
1832 |
- if (ist->st->codec->codec_type == ost->st->codec->codec_type) { |
|
1837 |
+ if ( ist->st->codec->codec_type == ost->st->codec->codec_type |
|
1838 |
+ && ist->st->discard != AVDISCARD_ALL) { |
|
1833 | 1839 |
ost->source_index = j; |
1834 | 1840 |
found = 1; |
1835 | 1841 |
} |
... | ... |
@@ -2909,10 +2889,27 @@ static void opt_input_file(const char *filename) |
2909 | 2909 |
av_exit(1); |
2910 | 2910 |
} |
2911 | 2911 |
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; |
|
2912 |
+ int i, j; |
|
2913 |
+ int found=0; |
|
2914 |
+ for(i=0; i<ic->nb_streams; i++){ |
|
2915 |
+ ic->streams[i]->discard= AVDISCARD_ALL; |
|
2916 |
+ } |
|
2917 |
+ for(i=0; i<ic->nb_programs; i++){ |
|
2918 |
+ AVProgram *p= ic->programs[i]; |
|
2919 |
+ if(p->id != opt_programid){ |
|
2920 |
+ p->discard = AVDISCARD_ALL; |
|
2921 |
+ }else{ |
|
2922 |
+ found=1; |
|
2923 |
+ for(j=0; j<p->nb_stream_indexes; j++){ |
|
2924 |
+ ic->streams[p->stream_index[j]]->discard= 0; |
|
2925 |
+ } |
|
2926 |
+ } |
|
2927 |
+ } |
|
2928 |
+ if(!found){ |
|
2929 |
+ fprintf(stderr, "Specified program id not found\n"); |
|
2930 |
+ av_exit(1); |
|
2931 |
+ } |
|
2932 |
+ opt_programid=0; |
|
2916 | 2933 |
} |
2917 | 2934 |
|
2918 | 2935 |
ic->loop_input = loop_input; |