Remove now redundant (and broken/undocumented) opt_programid.
---
Sorry, the first version was a little broken. Now i've found a file
with programs to test on, so it should work fine.
---
 avconv.c   |   44 +++++++++++++++++---------------------------
 cmdutils.c |   20 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/avconv.c b/avconv.c
index 8abb406..11ee381 100644
--- a/avconv.c
+++ b/avconv.c
@@ -141,7 +141,6 @@ static int copy_tb;
 static int opt_shortest = 0;
 static char *vstats_filename;
 static FILE *vstats_file;
-static int opt_programid = 0;
 static int copy_initial_nonkeyframes = 0;
 
 static int audio_volume = 256;
@@ -1891,7 +1890,7 @@ static int transcode_init(OutputFile *output_files,
                           InputFile *input_files,
                           int nb_input_files)
 {
-    int ret = 0, i, j;
+    int ret = 0, i, j, k;
     AVFormatContext *os;
     AVCodecContext *codec, *icodec;
     OutputStream *ost;
@@ -2189,6 +2188,22 @@ static int transcode_init(OutputFile *output_files,
         if ((ret = init_input_stream(i, output_streams, nb_output_streams, 
error, sizeof(error))) < 0)
             goto dump_format;
 
+    /* discard unused programs */
+    for (i = 0; i < nb_input_files; i++) {
+        InputFile *ifile = &input_files[i];
+        for (j = 0; j < ifile->ctx->nb_programs; j++) {
+            AVProgram *p = ifile->ctx->programs[j];
+            int discard  = AVDISCARD_ALL;
+
+            for (k = 0; k < p->nb_stream_indexes; k++)
+                if (!input_streams[ifile->ist_index + 
p->stream_index[k]].discard) {
+                    discard = AVDISCARD_DEFAULT;
+                    break;
+                }
+            p->discard = discard;
+        }
+    }
+
     /* open files and write file headers */
     for (i = 0; i < nb_output_files; i++) {
         os = output_files[i].ctx;
@@ -2909,30 +2924,6 @@ static int opt_input_file(OptionsContext *o, const char 
*opt, const char *filena
     }
     assert_avoptions(format_opts);
 
-    if(opt_programid) {
-        int i, j;
-        int found=0;
-        for(i=0; i<ic->nb_streams; i++){
-            ic->streams[i]->discard= AVDISCARD_ALL;
-        }
-        for(i=0; i<ic->nb_programs; i++){
-            AVProgram *p= ic->programs[i];
-            if(p->id != opt_programid){
-                p->discard = AVDISCARD_ALL;
-            }else{
-                found=1;
-                for(j=0; j<p->nb_stream_indexes; j++){
-                    ic->streams[p->stream_index[j]]->discard= 
AVDISCARD_DEFAULT;
-                }
-            }
-        }
-        if(!found){
-            fprintf(stderr, "Specified program id not found\n");
-            exit_program(1);
-        }
-        opt_programid=0;
-    }
-
     /* apply forced codec ids */
     for (i = 0; i < ic->nb_streams; i++)
         choose_codec(o, ic, ic->streams[i], ic->streams[i]->codec->codec_type);
@@ -4025,7 +4016,6 @@ static const OptionDef options[] = {
     { "copytb", OPT_BOOL | OPT_EXPERT, {(void*)&copy_tb}, "copy input stream 
time base when stream copying" },
     { "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", 
"threshold" },
-    { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, 
"desired program number", "" },
     { "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" },
     { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)&copy_initial_nonkeyframes}, 
"copy initial non-keyframes" },
     { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, 
"set the number of frames to record", "number" },
diff --git a/cmdutils.c b/cmdutils.c
index 2ab166e..132d060 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -864,6 +864,26 @@ int check_stream_specifier(AVFormatContext *s, AVStream 
*st, const char *spec)
             return 0;
         }
         return 1;
+    } else if (*spec == 'p' && *(spec + 1) == ':') {
+        int prog_id, i, j;
+        char *endptr;
+        spec += 2;
+        prog_id = strtol(spec, &endptr, 0);
+        for (i = 0; i < s->nb_programs; i++) {
+            if (s->programs[i]->id != prog_id)
+                continue;
+
+            if (*endptr++ == ':') {
+                int stream_idx = strtol(endptr, NULL, 0);
+                return (stream_idx >= 0 && stream_idx < 
s->programs[i]->nb_stream_indexes &&
+                        st->index == s->programs[i]->stream_index[stream_idx]);
+            }
+
+            for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)
+                if (st->index == s->programs[i]->stream_index[j])
+                    return 1;
+        }
+        return 0;
     } else if (!*spec) /* empty specifier, matches everything */
         return 1;
 
-- 
1.7.5.4

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to