Optimize encoding parameters for low-latency

This commit is contained in:
Cameron Gutman
2020-01-17 18:45:14 -08:00
parent 15dd6b3cd0
commit 32b6f8a395
6 changed files with 14 additions and 14 deletions

View File

@@ -14,8 +14,6 @@
namespace config {
using namespace std::literals;
video_t video {
16, // max_b_frames
24, // gop_size
35, // crf
35, // qp
@@ -158,8 +156,6 @@ void parse_file(const char *file) {
std::cout << "["sv << name << "] -- ["sv << val << ']' << std::endl;
}
int_f(vars, "max_b_frames", video.max_b_frames);
int_f(vars, "gop_size", video.gop_size);
int_f(vars, "crf", video.crf);
int_f(vars, "qp", video.qp);
int_f(vars, "threads", video.threads);

View File

@@ -7,8 +7,6 @@
namespace config {
struct video_t {
// ffmpeg params
int max_b_frames;
int gop_size;
int crf; // higher == more compression and less quality
int qp; // higher == more compression and less quality, ignored if crf != 0

View File

@@ -970,6 +970,7 @@ void cmd_announce(host_t &host, peer_t peer, msg_t &&req) {
config.monitor.framerate = util::from_view(args.at("x-nv-video[0].maxFPS"sv));
config.monitor.bitrate = util::from_view(args.at("x-nv-vqos[0].bw.maximumBitrateKbps"sv));
config.monitor.slicesPerFrame = util::from_view(args.at("x-nv-video[0].videoEncoderSlicesPerFrame"sv));
config.monitor.numRefFrames = util::from_view(args.at("x-nv-video[0].maxNumReferenceFrames"sv));
} catch(std::out_of_range &) {

View File

@@ -98,12 +98,20 @@ void encodeThread(
ctx->time_base = AVRational{1, framerate};
ctx->framerate = AVRational{framerate, 1};
ctx->pix_fmt = AV_PIX_FMT_YUV420P;
ctx->max_b_frames = config::video.max_b_frames;
ctx->has_b_frames = 1;
// B-frames delay decoder output, so never use them
ctx->max_b_frames = 0;
// Use an infinite GOP length since I-frames are generated on demand
ctx->gop_size = std::numeric_limits<int>::max();
ctx->keyint_min = ctx->gop_size;
// Some client decoders have limits on the number of reference frames
ctx->refs = config.numRefFrames;
ctx->slices = config.slicesPerFrame;
ctx->thread_type = FF_THREAD_SLICE;
ctx->thread_count = config::video.threads;
ctx->thread_count = std::min(ctx->slices, config::video.threads);
AVDictionary *options {nullptr};
@@ -119,11 +127,9 @@ void encodeThread(
ctx->rc_min_rate = config.bitrate;
}
else if(config::video.crf != 0) {
ctx->gop_size = config::video.gop_size;
av_dict_set_int(&options, "crf", config::video.crf, 0);
}
else {
ctx->gop_size = config::video.gop_size;
av_dict_set_int(&options, "qp", config::video.qp, 0);
}

View File

@@ -21,6 +21,7 @@ struct config_t {
int framerate;
int bitrate;
int slicesPerFrame;
int numRefFrames;
};
void capture_display(packet_queue_t packets, idr_event_t idr_events, config_t config);