Add config options to fine tune the x264 encoder
This commit is contained in:
@@ -19,6 +19,10 @@ video_t video {
|
|||||||
16, // max_b_frames
|
16, // max_b_frames
|
||||||
24, // gop_size
|
24, // gop_size
|
||||||
35, // crf
|
35, // crf
|
||||||
|
|
||||||
|
"baseline"s, // profile
|
||||||
|
"superfast"s, // preset
|
||||||
|
"zerolatency"s // tune
|
||||||
};
|
};
|
||||||
|
|
||||||
stream_t stream {
|
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, "max_b_frames", video.max_b_frames);
|
||||||
int_f(vars, "gop_size", video.gop_size);
|
int_f(vars, "gop_size", video.gop_size);
|
||||||
int_f(vars, "crf", video.crf);
|
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, "pkey", nvhttp.pkey);
|
||||||
string_f(vars, "cert", nvhttp.cert);
|
string_f(vars, "cert", nvhttp.cert);
|
||||||
|
|||||||
4
config.h
4
config.h
@@ -10,6 +10,10 @@ struct video_t {
|
|||||||
int max_b_frames;
|
int max_b_frames;
|
||||||
int gop_size;
|
int gop_size;
|
||||||
int crf; // higher == more compression and less quality
|
int crf; // higher == more compression and less quality
|
||||||
|
|
||||||
|
std::string profile;
|
||||||
|
std::string preset;
|
||||||
|
std::string tune;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stream_t {
|
struct stream_t {
|
||||||
|
|||||||
16
stream.cpp
16
stream.cpp
@@ -452,7 +452,7 @@ void controlThread() {
|
|||||||
session.client_state = 0;
|
session.client_state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
server.iterate(2s);
|
server.iterate(500ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +609,7 @@ void videoThread() {
|
|||||||
|
|
||||||
payload = {(char *) payload_new.data(), payload_new.size()};
|
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) {
|
for (auto x = shards.data_shards; x < shards.size(); ++x) {
|
||||||
video_packet_raw_t *inspect = (video_packet_raw_t *)shards[x].data();
|
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;
|
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.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.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.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.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(gcm_key), std::end(gcm_key), std::begin(session.gcm_key));
|
||||||
std::copy(std::begin(iv), std::end(iv), std::begin(session.iv));
|
std::copy(std::begin(iv), std::end(iv), std::begin(session.iv));
|
||||||
|
|
||||||
|
|||||||
@@ -26,4 +26,9 @@ gop_size = 24
|
|||||||
|
|
||||||
# Constant Rate Factor. Between 1 and 52.
|
# Constant Rate Factor. Between 1 and 52.
|
||||||
# Higher value means more compression, but less quality
|
# 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
|
||||||
|
|||||||
@@ -106,10 +106,11 @@ void encodeThread(
|
|||||||
ctx->thread_type = FF_THREAD_SLICE;
|
ctx->thread_type = FF_THREAD_SLICE;
|
||||||
ctx->thread_count = std::min(config.slicesPerFrame, 4);
|
ctx->thread_count = std::min(config.slicesPerFrame, 4);
|
||||||
|
|
||||||
|
|
||||||
AVDictionary *options {nullptr};
|
AVDictionary *options {nullptr};
|
||||||
av_dict_set(&options, "preset", "ultrafast", 0);
|
av_dict_set(&options, "profile", config::video.profile.c_str(), 0);
|
||||||
// av_dict_set(&options, "tune", "fastdecode", 0);
|
av_dict_set(&options, "preset", config::video.preset.c_str(), 0);
|
||||||
av_dict_set(&options, "profile", "baseline", 0);
|
av_dict_set(&options, "tune", config::video.tune.c_str(), 0);
|
||||||
|
|
||||||
av_dict_set_int(&options, "crf", config::video.crf, 0);
|
av_dict_set_int(&options, "crf", config::video.crf, 0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user