avconv: move ts scale to options context.
This commit is contained in:
32
avconv.c
32
avconv.c
@ -97,8 +97,6 @@ typedef struct MetadataMap {
|
|||||||
|
|
||||||
static const OptionDef options[];
|
static const OptionDef options[];
|
||||||
|
|
||||||
static AVDictionary *ts_scale;
|
|
||||||
|
|
||||||
/* indexed by output file stream index */
|
/* indexed by output file stream index */
|
||||||
static int *streamid_map = NULL;
|
static int *streamid_map = NULL;
|
||||||
static int nb_streamid_map = 0;
|
static int nb_streamid_map = 0;
|
||||||
@ -309,6 +307,9 @@ typedef struct OptionsContext {
|
|||||||
/* input options */
|
/* input options */
|
||||||
int64_t input_ts_offset;
|
int64_t input_ts_offset;
|
||||||
|
|
||||||
|
SpecifierOpt *ts_scale;
|
||||||
|
int nb_ts_scale;
|
||||||
|
|
||||||
/* output options */
|
/* output options */
|
||||||
StreamMap *stream_maps;
|
StreamMap *stream_maps;
|
||||||
int nb_stream_maps;
|
int nb_stream_maps;
|
||||||
@ -2360,12 +2361,10 @@ static int transcode(OutputFile *output_files,
|
|||||||
if (pkt.pts != AV_NOPTS_VALUE)
|
if (pkt.pts != AV_NOPTS_VALUE)
|
||||||
pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
|
pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
|
||||||
|
|
||||||
if (ist->ts_scale) {
|
|
||||||
if(pkt.pts != AV_NOPTS_VALUE)
|
if(pkt.pts != AV_NOPTS_VALUE)
|
||||||
pkt.pts *= ist->ts_scale;
|
pkt.pts *= ist->ts_scale;
|
||||||
if(pkt.dts != AV_NOPTS_VALUE)
|
if(pkt.dts != AV_NOPTS_VALUE)
|
||||||
pkt.dts *= ist->ts_scale;
|
pkt.dts *= ist->ts_scale;
|
||||||
}
|
|
||||||
|
|
||||||
// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files[ist->file_index].ts_offset, ist->st->codec->codec_type);
|
// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files[ist->file_index].ts_offset, ist->st->codec->codec_type);
|
||||||
if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE
|
if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE
|
||||||
@ -2783,11 +2782,6 @@ static int opt_map_metadata(OptionsContext *o, const char *opt, const char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int opt_input_ts_scale(const char *opt, const char *arg)
|
|
||||||
{
|
|
||||||
return av_dict_set(&ts_scale, opt, arg, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
|
static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
|
||||||
{
|
{
|
||||||
const char *codec_string = encoder ? "encoder" : "decoder";
|
const char *codec_string = encoder ? "encoder" : "decoder";
|
||||||
@ -2837,14 +2831,13 @@ static AVCodec *choose_codec(OptionsContext *o, AVFormatContext *s, AVStream *st
|
|||||||
*/
|
*/
|
||||||
static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
|
static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
|
||||||
{
|
{
|
||||||
int i, rfps, rfps_base, ret;
|
int i, rfps, rfps_base;
|
||||||
|
|
||||||
for (i = 0; i < ic->nb_streams; i++) {
|
for (i = 0; i < ic->nb_streams; i++) {
|
||||||
AVStream *st = ic->streams[i];
|
AVStream *st = ic->streams[i];
|
||||||
AVCodecContext *dec = st->codec;
|
AVCodecContext *dec = st->codec;
|
||||||
AVDictionaryEntry *e = NULL;
|
|
||||||
InputStream *ist;
|
InputStream *ist;
|
||||||
char *scale = NULL;
|
double scale = 1.0;
|
||||||
|
|
||||||
input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
|
input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
|
||||||
ist = &input_streams[nb_input_streams - 1];
|
ist = &input_streams[nb_input_streams - 1];
|
||||||
@ -2853,16 +2846,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
|
|||||||
ist->discard = 1;
|
ist->discard = 1;
|
||||||
ist->opts = filter_codec_opts(codec_opts, ist->st->codec->codec_id, ic, st);
|
ist->opts = filter_codec_opts(codec_opts, ist->st->codec->codec_id, ic, st);
|
||||||
|
|
||||||
while (e = av_dict_get(ts_scale, "", e, AV_DICT_IGNORE_SUFFIX)) {
|
MATCH_PER_STREAM_OPT(ts_scale, dbl, scale, ic, st);
|
||||||
char *p = strchr(e->key, ':');
|
ist->ts_scale = scale;
|
||||||
|
|
||||||
if ((ret = check_stream_specifier(ic, st, p ? p + 1 : "")) > 0)
|
|
||||||
scale = e->value;
|
|
||||||
else if (ret < 0)
|
|
||||||
exit_program(1);
|
|
||||||
}
|
|
||||||
if (scale)
|
|
||||||
ist->ts_scale = strtod(scale, NULL);
|
|
||||||
|
|
||||||
ist->dec = choose_codec(o, ic, st, dec->codec_type);
|
ist->dec = choose_codec(o, ic, st, dec->codec_type);
|
||||||
if (!ist->dec)
|
if (!ist->dec)
|
||||||
@ -3046,7 +3031,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
|
|||||||
audio_sample_rate = 0;
|
audio_sample_rate = 0;
|
||||||
audio_channels = 0;
|
audio_channels = 0;
|
||||||
audio_sample_fmt = AV_SAMPLE_FMT_NONE;
|
audio_sample_fmt = AV_SAMPLE_FMT_NONE;
|
||||||
av_dict_free(&ts_scale);
|
|
||||||
|
|
||||||
for (i = 0; i < orig_nb_streams; i++)
|
for (i = 0; i < orig_nb_streams; i++)
|
||||||
av_dict_free(&opts[i]);
|
av_dict_free(&opts[i]);
|
||||||
@ -4026,7 +4010,7 @@ static const OptionDef options[] = {
|
|||||||
{ "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET, {.off = OFFSET(limit_filesize)}, "set the limit file size in bytes", "limit_size" }, //
|
{ "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET, {.off = OFFSET(limit_filesize)}, "set the limit file size in bytes", "limit_size" }, //
|
||||||
{ "ss", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(start_time)}, "set the start time offset", "time_off" },
|
{ "ss", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(start_time)}, "set the start time offset", "time_off" },
|
||||||
{ "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(input_ts_offset)}, "set the input ts offset", "time_off" },
|
{ "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET, {.off = OFFSET(input_ts_offset)}, "set the input ts offset", "time_off" },
|
||||||
{ "itsscale", HAS_ARG, {(void*)opt_input_ts_scale}, "set the input ts scale", "scale" },
|
{ "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(ts_scale)}, "set the input ts scale", "scale" },
|
||||||
{ "metadata", HAS_ARG, {(void*)opt_metadata}, "add metadata", "string=string" },
|
{ "metadata", HAS_ARG, {(void*)opt_metadata}, "add metadata", "string=string" },
|
||||||
{ "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[AVMEDIA_TYPE_DATA]}, "set the number of data frames to record", "number" },
|
{ "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[AVMEDIA_TYPE_DATA]}, "set the number of data frames to record", "number" },
|
||||||
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
|
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
|
||||||
|
@ -258,6 +258,8 @@ unknown_opt:
|
|||||||
*(int64_t*)dst = parse_time_or_die(opt, arg, 1);
|
*(int64_t*)dst = parse_time_or_die(opt, arg, 1);
|
||||||
} else if (po->flags & OPT_FLOAT) {
|
} else if (po->flags & OPT_FLOAT) {
|
||||||
*(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
|
*(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
|
||||||
|
} else if (po->flags & OPT_DOUBLE) {
|
||||||
|
*(double*)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
|
||||||
} else if (po->u.func_arg) {
|
} else if (po->u.func_arg) {
|
||||||
int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) :
|
int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) :
|
||||||
po->u.func_arg(opt, arg);
|
po->u.func_arg(opt, arg);
|
||||||
|
@ -115,6 +115,7 @@ typedef struct SpecifierOpt {
|
|||||||
int i;
|
int i;
|
||||||
int64_t i64;
|
int64_t i64;
|
||||||
float f;
|
float f;
|
||||||
|
double dbl;
|
||||||
} u;
|
} u;
|
||||||
} SpecifierOpt;
|
} SpecifierOpt;
|
||||||
|
|
||||||
@ -140,6 +141,7 @@ typedef struct {
|
|||||||
Implies OPT_OFFSET. Next element after the offset is
|
Implies OPT_OFFSET. Next element after the offset is
|
||||||
an int containing element count in the array. */
|
an int containing element count in the array. */
|
||||||
#define OPT_TIME 0x10000
|
#define OPT_TIME 0x10000
|
||||||
|
#define OPT_DOUBLE 0x20000
|
||||||
union {
|
union {
|
||||||
void *dst_ptr;
|
void *dst_ptr;
|
||||||
int (*func_arg)(const char *, const char *);
|
int (*func_arg)(const char *, const char *);
|
||||||
|
Reference in New Issue
Block a user