| 1219 | } |
| 1220 | |
| 1221 | static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index) |
| 1222 | { |
| 1223 | OutputStream *ost; |
| 1224 | AVStream *st = avformat_new_stream(oc, NULL); |
| 1225 | int idx = oc->nb_streams - 1, ret = 0; |
| 1226 | const char *bsfs = NULL, *time_base = NULL; |
| 1227 | char *next, *codec_tag = NULL; |
| 1228 | double qscale = -1; |
| 1229 | int i; |
| 1230 | |
| 1231 | if (!st) { |
| 1232 | av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n"); |
| 1233 | exit_program(1); |
| 1234 | } |
| 1235 | |
| 1236 | if (oc->nb_streams - 1 < o->nb_streamid_map) |
| 1237 | st->id = o->streamid_map[oc->nb_streams - 1]; |
| 1238 | |
| 1239 | GROW_ARRAY(output_streams, nb_output_streams); |
| 1240 | if (!(ost = av_mallocz(sizeof(*ost)))) |
| 1241 | exit_program(1); |
| 1242 | output_streams[nb_output_streams - 1] = ost; |
| 1243 | |
| 1244 | ost->file_index = nb_output_files - 1; |
| 1245 | ost->index = idx; |
| 1246 | ost->st = st; |
| 1247 | st->codecpar->codec_type = type; |
| 1248 | |
| 1249 | ret = choose_encoder(o, oc, ost); |
| 1250 | if (ret < 0) { |
| 1251 | av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream " |
| 1252 | "%d:%d\n", ost->file_index, ost->index); |
| 1253 | exit_program(1); |
| 1254 | } |
| 1255 | |
| 1256 | ost->enc_ctx = avcodec_alloc_context3(ost->enc); |
| 1257 | if (!ost->enc_ctx) { |
| 1258 | av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n"); |
| 1259 | exit_program(1); |
| 1260 | } |
| 1261 | ost->enc_ctx->codec_type = type; |
| 1262 | |
| 1263 | ost->ref_par = avcodec_parameters_alloc(); |
| 1264 | if (!ost->ref_par) { |
| 1265 | av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n"); |
| 1266 | exit_program(1); |
| 1267 | } |
| 1268 | |
| 1269 | if (ost->enc) { |
| 1270 | AVIOContext *s = NULL; |
| 1271 | char *buf = NULL, *arg = NULL, *preset = NULL; |
| 1272 | |
| 1273 | ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc); |
| 1274 | |
| 1275 | MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); |
| 1276 | if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) { |
| 1277 | do { |
| 1278 | buf = get_line(s); |
no test coverage detected