+#include "x264_encoder.h"
+
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <x264.h>
+#include <cstdint>
#include "defs.h"
#include "flags.h"
#include "mux.h"
#include "timebase.h"
-#include "x264_encoder.h"
#include "x264_speed_control.h"
extern "C" {
+#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
// See if we have a new bitrate to change to.
unsigned new_rate = new_bitrate_kbit.exchange(0); // Read and clear.
if (new_rate != 0) {
- x264_param_t param;
- x264_encoder_parameters(x264, ¶m);
- param.rc.i_bitrate = new_rate;
- update_vbv_settings(¶m);
- x264_encoder_reconfig(x264, ¶m);
- printf("changing rate to %u\n", new_rate);
+ if (speed_control) {
+ speed_control->set_config_override_function([new_rate](x264_param_t *param) {
+ param->rc.i_bitrate = new_rate;
+ update_vbv_settings(param);
+ });
+ } else {
+ x264_param_t param;
+ x264_encoder_parameters(x264, ¶m);
+ param.rc.i_bitrate = new_rate;
+ update_vbv_settings(¶m);
+ x264_encoder_reconfig(x264, ¶m);
+ }
}
if (speed_control) {