]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9487 #resolve [Add CBR param to video file recording params]
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 7 Sep 2016 21:48:55 +0000 (16:48 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 7 Sep 2016 21:49:04 +0000 (16:49 -0500)
src/include/switch_module_interfaces.h
src/mod/applications/mod_av/avformat.c
src/switch_core_file.c

index 1d57abe540dfbcc677207cd433ad91b5ae51f02c..1802f872e3fc2ceda8baf7d42a7e720d3565c12e 100644 (file)
@@ -321,6 +321,7 @@ typedef struct switch_mm_s {
        int vb;
        int vw;
        int vh;
+       int cbr;
        float fps;
        float source_fps;
        int vbuf;
index 7546ad6391ed4fed7ecd6dafdda4cd5563a7b734..264dd33e151e4da5fd164424b55ca8a37a087672 100644 (file)
@@ -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;
index ce75674572e21af72783190adb3da84d915270a0..49ff70b7d174c4ae1d83906c23316563334b90b3 100644 (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"))) {
                        tmp = atoi(val);