History

avconv: only apply presets when we have an encoder.

Fixes a crash when using a preset with stream copy.

Anton Khirnov committed 14 years ago

Commit 4e61a381 parent a1f4cd31 file · +28 −27Browse files

Unified · Split

avconv_opt.c+28−27
@@ -754,8 +754,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e · 753 unmodified lines
754754 char *bsf = NULL, *next, *codec_tag = NULL;
755755 AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
756756 double qscale = -1;
757− char *buf = NULL, *arg = NULL, *preset = NULL;
758− AVIOContext *s = NULL;
759757
760758 if (!st) {
761759 av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
@@ -777,37 +775,40 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e · 15 unmodified lines
777775 st->codec->codec_type = type;
778776 choose_encoder(o, oc, ost);
779777 if (ost->enc) {
778+ AVIOContext *s = NULL;
779+ char *buf = NULL, *arg = NULL, *preset = NULL;
780+
780781 ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st, ost->enc);
782+
783+ MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
784+ if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
785+ do {
786+ buf = get_line(s);
787+ if (!buf[0] || buf[0] == '#') {
788+ av_free(buf);
789+ continue;
790+ }
791+ if (!(arg = strchr(buf, '='))) {
792+ av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
793+ exit(1);
794+ }
795+ *arg++ = 0;
796+ av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
797+ av_free(buf);
798+ } while (!s->eof_reached);
799+ avio_close(s);
800+ }
801+ if (ret) {
802+ av_log(NULL, AV_LOG_FATAL,
803+ "Preset %s specified for stream %d:%d, but could not be opened.\n",
804+ preset, ost->file_index, ost->index);
805+ exit(1);
806+ }
781807 }
782808
783809 avcodec_get_context_defaults3(st->codec, ost->enc);
784810 st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy
785811
786− MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
787− if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
788− do {
789− buf = get_line(s);
790− if (!buf[0] || buf[0] == '#') {
791− av_free(buf);
792− continue;
793− }
794− if (!(arg = strchr(buf, '='))) {
795− av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
796− exit(1);
797− }
798− *arg++ = 0;
799− av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
800− av_free(buf);
801− } while (!s->eof_reached);
802− avio_close(s);
803− }
804− if (ret) {
805− av_log(NULL, AV_LOG_FATAL,
806− "Preset %s specified for stream %d:%d, but could not be opened.\n",
807− preset, ost->file_index, ost->index);
808− exit(1);
809− }
810−
811812 ost->max_frames = INT64_MAX;
812813 MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
813814

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t