Set custom options (some codecs accept additional params)
| 333 | |
| 334 | // Set custom options (some codecs accept additional params) |
| 335 | void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string value) { |
| 336 | // Declare codec context |
| 337 | AVCodecContext *c = NULL; |
| 338 | AVStream *st = NULL; |
| 339 | std::stringstream convert(value); |
| 340 | |
| 341 | if (info.has_video && stream == VIDEO_STREAM && video_st) { |
| 342 | st = video_st; |
| 343 | // Get codec context |
| 344 | c = AV_GET_CODEC_PAR_CONTEXT(st, video_codec_ctx); |
| 345 | // Was a codec / stream found? |
| 346 | if (c) { |
| 347 | if (info.interlaced_frame) { |
| 348 | c->field_order = info.top_field_first ? AV_FIELD_TT : AV_FIELD_BB; |
| 349 | // We only use these two version and ignore AV_FIELD_TB and AV_FIELD_BT |
| 350 | // Otherwise we would need to change the whole export window |
| 351 | } |
| 352 | } |
| 353 | } else if (info.has_audio && stream == AUDIO_STREAM && audio_st) { |
| 354 | st = audio_st; |
| 355 | // Get codec context |
| 356 | c = AV_GET_CODEC_PAR_CONTEXT(st, audio_codec_ctx); |
| 357 | } else |
| 358 | throw NoStreamsFound("The stream was not found. Be sure to call PrepareStreams() first.", path); |
| 359 | |
| 360 | // Init AVOption |
| 361 | const AVOption *option = NULL; |
| 362 | |
| 363 | // Was a codec / stream found? |
| 364 | if (c) |
| 365 | // Find AVOption (if it exists) |
| 366 | option = AV_OPTION_FIND(c->priv_data, name.c_str()); |
| 367 | |
| 368 | // Was option found? |
| 369 | if (option || (name == "g" || name == "qmin" || name == "qmax" || name == "max_b_frames" || name == "mb_decision" || |
| 370 | name == "level" || name == "profile" || name == "slices" || name == "rc_min_rate" || name == "rc_max_rate" || |
| 371 | name == "rc_buffer_size" || name == "crf" || name == "cqp" || name == "qp" || name == "allow_b_frames")) { |
| 372 | // Check for specific named options |
| 373 | if (name == "g") |
| 374 | // Set gop_size |
| 375 | convert >> c->gop_size; |
| 376 | |
| 377 | else if (name == "qmin") |
| 378 | // Minimum quantizer |
| 379 | convert >> c->qmin; |
| 380 | |
| 381 | else if (name == "qmax") |
| 382 | // Maximum quantizer |
| 383 | convert >> c->qmax; |
| 384 | |
| 385 | else if (name == "max_b_frames") |
| 386 | // Maximum number of B-frames between non-B-frames |
| 387 | convert >> c->max_b_frames; |
| 388 | |
| 389 | else if (name == "allow_b_frames") |
| 390 | // Preserve configured B-frames for codecs that support them. |
| 391 | // Values: 1/true/yes/on to enable, everything else disables. |
| 392 | allow_b_frames = (value == "1" || value == "true" || value == "yes" || value == "on"); |
no test coverage detected