FS-9487 #resolve [Add CBR param to video file recording params]

This commit is contained in:
Anthony Minessale 2016-09-07 16:48:55 -05:00
parent 1e867a85f8
commit d3ee9adfd1
3 changed files with 24 additions and 10 deletions

View File

@ -321,6 +321,7 @@ typedef struct switch_mm_s {
int vb; int vb;
int vw; int vw;
int vh; int vh;
int cbr;
float fps; float fps;
float source_fps; float source_fps;
int vbuf; int vbuf;

View File

@ -353,7 +353,7 @@ static switch_status_t add_stream(MediaStream *mst, AVFormatContext *fc, AVCodec
/* Resolution must be a multiple of two. */ /* Resolution must be a multiple of two. */
c->width = mst->width; c->width = mst->width;
c->height = mst->height; 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.den = 1000;
mst->st->time_base.num = 1; mst->st->time_base.num = 1;
c->time_base.den = 1000; 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) { if (codec_id == AV_CODEC_ID_VP8) {
av_set_options_string(c, "quality=realtime", "=", ":"); 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.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) { if (fmt->video_codec != AV_CODEC_ID_NONE) {
const AVCodecDescriptor *desc; const AVCodecDescriptor *desc;

View File

@ -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"))) { if ((val = switch_event_get_header(fh->params, "vb"))) {
tmp = atoi(val); tmp = atoi(val);