avconv: only apply presets when we have an encoder.
Fixes a crash when using a preset with stream copy. (cherry picked from commit 4e61a38aa038b7027c5ed423635168d463515d24) Signed-off-by: Reinhard Tartler <siretart@tauware.de>
This commit is contained in:
parent
0ba0e31955
commit
50b8e4c8fd
55
avconv.c
55
avconv.c
@ -3468,8 +3468,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
|
|||||||
char *bsf = NULL, *next, *codec_tag = NULL;
|
char *bsf = NULL, *next, *codec_tag = NULL;
|
||||||
AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
|
AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
|
||||||
double qscale = -1;
|
double qscale = -1;
|
||||||
char *buf = NULL, *arg = NULL, *preset = NULL;
|
|
||||||
AVIOContext *s = NULL;
|
|
||||||
|
|
||||||
if (!st) {
|
if (!st) {
|
||||||
av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
|
av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
|
||||||
@ -3488,37 +3486,40 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
|
|||||||
st->codec->codec_type = type;
|
st->codec->codec_type = type;
|
||||||
choose_encoder(o, oc, ost);
|
choose_encoder(o, oc, ost);
|
||||||
if (ost->enc) {
|
if (ost->enc) {
|
||||||
|
AVIOContext *s = NULL;
|
||||||
|
char *buf = NULL, *arg = NULL, *preset = NULL;
|
||||||
|
|
||||||
ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
|
ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
|
||||||
|
|
||||||
|
MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
|
||||||
|
if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
|
||||||
|
do {
|
||||||
|
buf = get_line(s);
|
||||||
|
if (!buf[0] || buf[0] == '#') {
|
||||||
|
av_free(buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(arg = strchr(buf, '='))) {
|
||||||
|
av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
|
||||||
|
exit_program(1);
|
||||||
|
}
|
||||||
|
*arg++ = 0;
|
||||||
|
av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
|
||||||
|
av_free(buf);
|
||||||
|
} while (!s->eof_reached);
|
||||||
|
avio_close(s);
|
||||||
|
}
|
||||||
|
if (ret) {
|
||||||
|
av_log(NULL, AV_LOG_FATAL,
|
||||||
|
"Preset %s specified for stream %d:%d, but could not be opened.\n",
|
||||||
|
preset, ost->file_index, ost->index);
|
||||||
|
exit_program(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
avcodec_get_context_defaults3(st->codec, ost->enc);
|
avcodec_get_context_defaults3(st->codec, ost->enc);
|
||||||
st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy
|
st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
|
|
||||||
if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
|
|
||||||
do {
|
|
||||||
buf = get_line(s);
|
|
||||||
if (!buf[0] || buf[0] == '#') {
|
|
||||||
av_free(buf);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!(arg = strchr(buf, '='))) {
|
|
||||||
av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
|
|
||||||
exit_program(1);
|
|
||||||
}
|
|
||||||
*arg++ = 0;
|
|
||||||
av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
|
|
||||||
av_free(buf);
|
|
||||||
} while (!s->eof_reached);
|
|
||||||
avio_close(s);
|
|
||||||
}
|
|
||||||
if (ret) {
|
|
||||||
av_log(NULL, AV_LOG_FATAL,
|
|
||||||
"Preset %s specified for stream %d:%d, but could not be opened.\n",
|
|
||||||
preset, ost->file_index, ost->index);
|
|
||||||
exit_program(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ost->max_frames = INT64_MAX;
|
ost->max_frames = INT64_MAX;
|
||||||
MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
|
MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user