diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 1d57abe540..1802f872e3 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -321,6 +321,7 @@ typedef struct switch_mm_s { int vb; int vw; int vh; + int cbr; float fps; float source_fps; int vbuf; diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 7546ad6391..264dd33e15 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -353,7 +353,7 @@ static switch_status_t add_stream(MediaStream *mst, AVFormatContext *fc, AVCodec /* Resolution must be a multiple of two. */ c->width = mst->width; c->height = mst->height; - c->bit_rate = switch_calc_bitrate(c->width, c->height, 2, fps) * 1024; + c->bit_rate = mm->vb; mst->st->time_base.den = 1000; mst->st->time_base.num = 1; c->time_base.den = 1000; @@ -409,15 +409,22 @@ static switch_status_t add_stream(MediaStream *mst, AVFormatContext *fc, AVCodec } } - c->gop_size = 250; // g=250 - c->keyint_min = 25; // keyint_min=25 - c->i_quant_factor = 0.71; // i_qfactor=0.71 - c->qcompress = 0.6; // qcomp=0.6 - c->qmin = 10; // qmin=10 - c->qmax = 31; // qmax=31 - c->max_qdiff = 4; // qdiff=4 - av_opt_set_int(c->priv_data, "crf", 18, 0); + if (mm->cbr) { + c->rc_min_rate = c->bit_rate; + c->rc_max_rate = c->bit_rate; + c->rc_buffer_size = c->bit_rate; + c->qcompress = 0; + } else { + c->gop_size = 250; // g=250 + c->keyint_min = 25; // keyint_min=25 + c->i_quant_factor = 0.71; // i_qfactor=0.71 + c->qcompress = 0.6; // qcomp=0.6 + c->qmin = 10; // qmin=10 + c->qmax = 31; // qmax=31 + c->max_qdiff = 4; // qdiff=4 + av_opt_set_int(c->priv_data, "crf", 18, 0); + } if (codec_id == AV_CODEC_ID_VP8) { av_set_options_string(c, "quality=realtime", "=", ":"); @@ -1753,7 +1760,9 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa handle->mm.ab = 128; } - handle->mm.vb = switch_calc_bitrate(handle->mm.vw, handle->mm.vh, 1, handle->mm.fps); + if (!handle->mm.vb) { + handle->mm.vb = switch_calc_bitrate(handle->mm.vw, handle->mm.vh, 1, handle->mm.fps); + } if (fmt->video_codec != AV_CODEC_ID_NONE) { const AVCodecDescriptor *desc; diff --git a/src/switch_core_file.c b/src/switch_core_file.c index ce75674572..49ff70b7d1 100644 --- a/src/switch_core_file.c +++ b/src/switch_core_file.c @@ -142,6 +142,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, } } + if ((val = switch_event_get_header(fh->params, "cbr"))) { + tmp = switch_true(val); + fh->mm.cbr = tmp; + } if ((val = switch_event_get_header(fh->params, "vb"))) { tmp = atoi(val);