summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-08-31 22:24:06 +0200
committerAnton Khirnov <anton@khirnov.net>2011-09-11 17:30:01 +0200
commit2c474ddbc5b90541ea4a65961490b6469d12529f (patch)
treea2e7ace7cf4ee1c6897a698ffb7af9e71d6ed590
parent05bffc12c4faff47aabe08bafe44ee3b31ed5b47 (diff)
cmdutils: add support for programs in check_stream_specifier()
Remove now redundant (and broken/undocumented) opt_programid.
-rw-r--r--avconv.c44
-rw-r--r--cmdutils.c20
2 files changed, 37 insertions, 27 deletions
diff --git a/avconv.c b/avconv.c
index a02d36bb30..984c263d0c 100644
--- a/avconv.c
+++ b/avconv.c
@@ -140,7 +140,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;
@@ -1892,7 +1891,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;
@@ -2190,6 +2189,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;
@@ -2904,30 +2919,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);
@@ -4018,7 +4009,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 2aab395a96..16b64aff23 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -841,6 +841,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;