aboutsummaryrefslogtreecommitdiffstats
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorNico Sabbi <nicola.sabbi@poste.it>2007-10-27 18:46:25 +0000
committerNico Sabbi <nicola.sabbi@poste.it>2007-10-27 18:46:25 +0000
commit50e143c4be35e05f90f6bd9c2fc71a37badaff48 (patch)
treebdd214050587bdb16e58f7004f81eccae0d9bec4 /ffmpeg.c
parent90f03441654f85a1402a65c3dcaa3f634a24c27e (diff)
downloadffmpeg-50e143c4be35e05f90f6bd9c2fc71a37badaff48.tar.gz
added option programid to select the program to use and relative code to handle it
Originally committed as revision 10866 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index e7fcf87a5e..347348f70b 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -187,6 +187,7 @@ static int opt_shortest = 0; //
static int video_global_header = 0;
static char *vstats_filename;
static FILE *vstats_file;
+static int opt_programid = 0;
static int rate_emu = 0;
@@ -1350,6 +1351,33 @@ static void print_sdp(AVFormatContext **avc, int n)
printf("SDP:\n%s\n", sdp);
}
+static int stream_index_from_inputs(AVFormatContext **input_files,
+ int nb_input_files,
+ AVInputFile *file_table,
+ AVInputStream **ist_table,
+ enum CodecType type,
+ int programid)
+{
+ int p, q, r, s, z;
+ AVInputStream *ist;
+ for(z=0; z<nb_input_files; z++) {
+ AVFormatContext *ic = input_files[z];
+ for(p=0; p<ic->nb_programs; p++) {
+ AVProgram *program = ic->programs[p];
+ if(program->id != programid)
+ continue;
+ for(q=0; q<program->nb_stream_indexes; q++) {
+ int sidx = program->stream_index[q];
+ int ris = file_table[z].ist_index + sidx;
+ if(ist_table[ris]->discard && ic->streams[sidx]->codec->codec_type == type)
+ return ris;
+ }
+ }
+ }
+
+ return -1;
+}
+
/*
* The following code is the main loop of the file converter
*/
@@ -1476,6 +1504,14 @@ static int av_encode(AVFormatContext **output_files,
}
} else {
+ if(opt_programid) {
+ found = 0;
+ j = stream_index_from_inputs(input_files, nb_input_files, file_table, ist_table, ost->st->codec->codec_type, opt_programid);
+ if(j != -1) {
+ ost->source_index = j;
+ found = 1;
+ }
+ } else {
/* get corresponding input stream index : we select the first one with the right type */
found = 0;
for(j=0;j<nb_istreams;j++) {
@@ -1487,8 +1523,10 @@ static int av_encode(AVFormatContext **output_files,
break;
}
}
+ }
if (!found) {
+ if(! opt_programid) {
/* try again and reuse existing stream */
for(j=0;j<nb_istreams;j++) {
ist = ist_table[j];
@@ -1497,6 +1535,7 @@ static int av_encode(AVFormatContext **output_files,
found = 1;
}
}
+ }
if (!found) {
fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n",
ost->file_index, ost->index);
@@ -2590,6 +2629,12 @@ static void opt_input_file(const char *filename)
print_error(filename, err);
exit(1);
}
+ if(opt_programid) {
+ int i;
+ for(i=0; i<ic->nb_programs; i++)
+ if(ic->programs[i]->id != opt_programid)
+ ic->programs[i]->discard = AVDISCARD_ALL;
+ }
ic->loop_input = loop_input;
@@ -3635,6 +3680,7 @@ const OptionDef options[] = {
{ "copyts", OPT_BOOL | OPT_EXPERT, {(void*)&copy_ts}, "copy timestamps" },
{ "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
{ "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" },
+ { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" },
/* video options */
{ "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" },