You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
fftools/ffmpeg_opt: reimplement -streamid using a dictionary
This does not require an arbitrary limit on the number of streams. Also, return error codes from opt_streamid() instead of aborting.
This commit is contained in:
@@ -72,8 +72,6 @@ enum EncTimeBase {
|
|||||||
ENC_TIME_BASE_FILTER = -2,
|
ENC_TIME_BASE_FILTER = -2,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_STREAMS 1024 /* arbitrary sanity check value */
|
|
||||||
|
|
||||||
enum HWAccelID {
|
enum HWAccelID {
|
||||||
HWACCEL_NONE = 0,
|
HWACCEL_NONE = 0,
|
||||||
HWACCEL_AUTO,
|
HWACCEL_AUTO,
|
||||||
@@ -183,9 +181,8 @@ typedef struct OptionsContext {
|
|||||||
int subtitle_disable;
|
int subtitle_disable;
|
||||||
int data_disable;
|
int data_disable;
|
||||||
|
|
||||||
/* indexed by output file stream index */
|
// keys are stream indices
|
||||||
int *streamid_map;
|
AVDictionary *streamid;
|
||||||
int nb_streamid_map;
|
|
||||||
|
|
||||||
SpecifierOpt *metadata;
|
SpecifierOpt *metadata;
|
||||||
int nb_metadata;
|
int nb_metadata;
|
||||||
|
@@ -1100,12 +1100,24 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
|
|||||||
if (!st)
|
if (!st)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
if (oc->nb_streams - 1 < o->nb_streamid_map)
|
|
||||||
st->id = o->streamid_map[oc->nb_streams - 1];
|
|
||||||
|
|
||||||
ms = mux_stream_alloc(mux, type);
|
ms = mux_stream_alloc(mux, type);
|
||||||
ost = &ms->ost;
|
ost = &ms->ost;
|
||||||
|
|
||||||
|
if (o->streamid) {
|
||||||
|
AVDictionaryEntry *e;
|
||||||
|
char idx[16], *p;
|
||||||
|
snprintf(idx, sizeof(idx), "%d", ost->index);
|
||||||
|
|
||||||
|
e = av_dict_get(o->streamid, idx, NULL, 0);
|
||||||
|
if (e) {
|
||||||
|
st->id = strtol(e->value, &p, 0);
|
||||||
|
if (!e->value[0] || *p) {
|
||||||
|
av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value);
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ost->par_in = avcodec_parameters_alloc();
|
ost->par_in = avcodec_parameters_alloc();
|
||||||
if (!ost->par_in)
|
if (!ost->par_in)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
@@ -128,8 +128,9 @@ static void uninit_options(OptionsContext *o)
|
|||||||
#if FFMPEG_OPT_MAP_CHANNEL
|
#if FFMPEG_OPT_MAP_CHANNEL
|
||||||
av_freep(&o->audio_channel_maps);
|
av_freep(&o->audio_channel_maps);
|
||||||
#endif
|
#endif
|
||||||
av_freep(&o->streamid_map);
|
|
||||||
av_freep(&o->attachments);
|
av_freep(&o->attachments);
|
||||||
|
|
||||||
|
av_dict_free(&o->streamid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_options(OptionsContext *o)
|
static void init_options(OptionsContext *o)
|
||||||
@@ -727,7 +728,6 @@ char *file_read(const char *filename)
|
|||||||
static int opt_streamid(void *optctx, const char *opt, const char *arg)
|
static int opt_streamid(void *optctx, const char *opt, const char *arg)
|
||||||
{
|
{
|
||||||
OptionsContext *o = optctx;
|
OptionsContext *o = optctx;
|
||||||
int idx;
|
|
||||||
char *p;
|
char *p;
|
||||||
char idx_str[16];
|
char idx_str[16];
|
||||||
|
|
||||||
@@ -737,13 +737,11 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg)
|
|||||||
av_log(NULL, AV_LOG_FATAL,
|
av_log(NULL, AV_LOG_FATAL,
|
||||||
"Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
|
"Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
|
||||||
arg, opt);
|
arg, opt);
|
||||||
exit_program(1);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
|
|
||||||
o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
|
return av_dict_set(&o->streamid, idx_str, p, 0);
|
||||||
o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_complex_filters(void)
|
static int init_complex_filters(void)
|
||||||
|
Reference in New Issue
Block a user