Add config options to fine tune the x264 encoder

This commit is contained in:
loki 2019-12-06 20:52:08 +01:00
parent f9c76828d4
commit d0f0e0b239
5 changed files with 29 additions and 12 deletions

View File

@ -19,6 +19,10 @@ video_t video {
16, // max_b_frames
24, // gop_size
35, // crf
"baseline"s, // profile
"superfast"s, // preset
"zerolatency"s // tune
};
stream_t stream {
@ -114,6 +118,9 @@ void parse_file(const char *file) {
int_f(vars, "max_b_frames", video.max_b_frames);
int_f(vars, "gop_size", video.gop_size);
int_f(vars, "crf", video.crf);
string_f(vars, "profile", video.profile);
string_f(vars, "preset", video.preset);
string_f(vars, "tune", video.tune);
string_f(vars, "pkey", nvhttp.pkey);
string_f(vars, "cert", nvhttp.cert);

View File

@ -10,6 +10,10 @@ struct video_t {
int max_b_frames;
int gop_size;
int crf; // higher == more compression and less quality
std::string profile;
std::string preset;
std::string tune;
};
struct stream_t {

View File

@ -452,7 +452,7 @@ void controlThread() {
session.client_state = 0;
}
server.iterate(2s);
server.iterate(500ms);
}
}
@ -609,7 +609,7 @@ void videoThread() {
payload = {(char *) payload_new.data(), payload_new.size()};
auto shards = fec::encode(payload, blocksize, 25);
auto shards = fec::encode(payload, blocksize, fecpercentage);
for (auto x = shards.data_shards; x < shards.size(); ++x) {
video_packet_raw_t *inspect = (video_packet_raw_t *)shards[x].data();
@ -781,18 +781,18 @@ void cmd_announce(tcp::socket &&sock, msg_t &&req) {
}
auto &config = session.config;
config.monitor.height = util::from_view(args.at("x-nv-video[0].clientViewportHt"sv));
config.monitor.width = util::from_view(args.at("x-nv-video[0].clientViewportWd"sv));
config.monitor.framerate = util::from_view(args.at("x-nv-video[0].maxFPS"sv));
config.monitor.bitrate = util::from_view(args.at("x-nv-video[0].initialBitrateKbps"sv));
config.monitor.slicesPerFrame = util::from_view(args.at("x-nv-video[0].videoEncoderSlicesPerFrame"sv));
config.audio.channels = util::from_view(args.at("x-nv-audio.surround.numChannels"sv));
config.audio.mask = util::from_view(args.at("x-nv-audio.surround.channelMask"sv));
config.audio.packetDuration = util::from_view(args.at("x-nv-aqos.packetDuration"sv));
config.packetsize = util::from_view(args.at("x-nv-video[0].packetSize"sv));
config.monitor.height = util::from_view(args.at("x-nv-video[0].clientViewportHt"sv));
config.monitor.width = util::from_view(args.at("x-nv-video[0].clientViewportWd"sv));
config.monitor.framerate = util::from_view(args.at("x-nv-video[0].maxFPS"sv));
config.monitor.bitrate = util::from_view(args.at("x-nv-video[0].initialBitrateKbps"sv));
config.monitor.slicesPerFrame = util::from_view(args.at("x-nv-video[0].videoEncoderSlicesPerFrame"sv));
std::copy(std::begin(gcm_key), std::end(gcm_key), std::begin(session.gcm_key));
std::copy(std::begin(iv), std::end(iv), std::begin(session.iv));

View File

@ -26,4 +26,9 @@ gop_size = 24
# Constant Rate Factor. Between 1 and 52.
# Higher value means more compression, but less quality
crf = 35
crf = 28
# See x264 --fullhelp for the different presets
# profile = baseline
# preset = superfast
# tune = zerolatency

View File

@ -106,10 +106,11 @@ void encodeThread(
ctx->thread_type = FF_THREAD_SLICE;
ctx->thread_count = std::min(config.slicesPerFrame, 4);
AVDictionary *options {nullptr};
av_dict_set(&options, "preset", "ultrafast", 0);
// av_dict_set(&options, "tune", "fastdecode", 0);
av_dict_set(&options, "profile", "baseline", 0);
av_dict_set(&options, "profile", config::video.profile.c_str(), 0);
av_dict_set(&options, "preset", config::video.preset.c_str(), 0);
av_dict_set(&options, "tune", config::video.tune.c_str(), 0);
av_dict_set_int(&options, "crf", config::video.crf, 0);