Fixes a crash when using a preset with stream copy.
Unified · Split
| @@ -754,8 +754,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e · 753 unmodified lines | |||
| 754 | char *bsf = NULL, *next, *codec_tag = NULL; | 754 | char *bsf = NULL, *next, *codec_tag = NULL; |
| 755 | AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL; | 755 | AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL; |
| 756 | double qscale = -1; | 756 | double qscale = -1; |
| 757 | char *buf = NULL, *arg = NULL, *preset = NULL; | ||
| 758 | AVIOContext *s = NULL; | ||
| 759 | 757 | ||
| 760 | if (!st) { | 758 | if (!st) { |
| 761 | av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n"); | 759 | 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 | |||
| 777 | st->codec->codec_type = type; | 775 | st->codec->codec_type = type; |
| 778 | choose_encoder(o, oc, ost); | 776 | choose_encoder(o, oc, ost); |
| 779 | if (ost->enc) { | 777 | if (ost->enc) { |
| 778 | AVIOContext *s = NULL; | ||
| 779 | char *buf = NULL, *arg = NULL, *preset = NULL; | ||
| 780 | |||
| 780 | ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st, ost->enc); | 781 | 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 | } | ||
| 781 | } | 807 | } |
| 782 | 808 | ||
| 783 | avcodec_get_context_defaults3(st->codec, ost->enc); | 809 | avcodec_get_context_defaults3(st->codec, ost->enc); |
| 784 | st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy | 810 | st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy |
| 785 | 811 | ||
| 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 | |||
| 811 | ost->max_frames = INT64_MAX; | 812 | ost->max_frames = INT64_MAX; |
| 812 | MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); | 813 | MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); |
| 813 | 814 | ||