Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newer codecs (svt_av1, rav1e, svt_hevc) #445

Merged
merged 7 commits into from
Jun 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/FFmpegWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void FFmpegWriter::SetVideoOptions(bool has_video, std::string codec, Fraction f
}
if (bit_rate >= 1000) // bit_rate is the bitrate in b/s
info.video_bit_rate = bit_rate;
if ((bit_rate >= 0) && (bit_rate < 64)) // bit_rate is the bitrate in crf
if ((bit_rate >= 0) && (bit_rate < 256)) // bit_rate is the bitrate in crf
info.video_bit_rate = bit_rate;

info.interlaced_frame = interlaced;
Expand Down Expand Up @@ -341,7 +341,7 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va
// Was option found?
if (option || (name == "g" || name == "qmin" || name == "qmax" || name == "max_b_frames" || name == "mb_decision" ||
name == "level" || name == "profile" || name == "slices" || name == "rc_min_rate" || name == "rc_max_rate" ||
name == "rc_buffer_size" || name == "crf" || name == "cqp")) {
name == "rc_buffer_size" || name == "crf" || name == "cqp" || name == "qp")) {
// Check for specific named options
if (name == "g")
// Set gop_size
Expand Down Expand Up @@ -462,6 +462,18 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va
case AV_CODEC_ID_AV1 :
c->bit_rate = 0;
av_opt_set_int(c->priv_data, "crf", std::min(std::stoi(value),63), 0);
if (strstr(info.vcodec.c_str(), "svt_av1") != NULL) {
//av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),63), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

Suggested change
//av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),63), 0);

av_opt_set_int(c->priv_data, "preset", 6, 0);
av_opt_set_int(c->priv_data, "forced-idr",1,0);
}
if (strstr(info.vcodec.c_str(), "rav1e") != NULL) {
//av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),255), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Suggested change
//av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),255), 0);

av_opt_set_int(c->priv_data, "speed", 7, 0);
av_opt_set_int(c->priv_data, "tile-rows", 2, 0);
av_opt_set_int(c->priv_data, "tile-columns", 4, 0);
//av_opt_set(c->priv_data, "tile-row", "", 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's 'tile-row'? I saw it commented out in a few places.

}
break;
#endif
case AV_CODEC_ID_VP8 :
Expand Down Expand Up @@ -503,6 +515,36 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va
c->bit_rate = (int) (mbs);
}
}
#endif
} else if (name == "qp") {
// encode quality and special settings like lossless
// This might be better in an extra methods as more options
// and way to set quality are possible
#if (LIBAVCODEC_VERSION_MAJOR >= 58)
switch (c->codec_id) {
case AV_CODEC_ID_AV1 :
c->bit_rate = 0;
av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),63), 0);
if (strstr(info.vcodec.c_str(), "svt_av1") != NULL) {
av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),63), 0);
av_opt_set_int(c->priv_data, "preset", 6, 0);
av_opt_set_int(c->priv_data, "forced-idr",1,0);
}
if (strstr(info.vcodec.c_str(), "rav1e") != NULL) {
av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),255), 0);
av_opt_set_int(c->priv_data, "speed", 7, 0);
av_opt_set_int(c->priv_data, "tile-rows", 2, 0);
av_opt_set_int(c->priv_data, "tile-columns", 4, 0);
//av_opt_set(c->priv_data, "tile-row", "", 0);
}
if (strstr(info.vcodec.c_str(), "aom") != NULL) {
// Hack to set tiles; libaom doesn have qp only crf
av_opt_set_int(c->priv_data, "crf", std::min(std::stoi(value),63), 0);
av_opt_set_int(c->priv_data, "tile-rows", 1, 0); // log2 of number of rows
av_opt_set_int(c->priv_data, "tile-columns", 2, 0); // log2 of number of columns
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Hack to set tiles?" So if I'm understanding this right, when using the aom codec:

// Encode with a CRF of 15 and.... (no? default?) tiling
writer.setOption(VIDEO_STREAM, "crf", 15)
// Encode with a CRF of 15 and tile-rows=1, tile-columns=2
writer.setOption(VIDEO_STREAM, "qp", 15)

Is that right? Feels a bit magical for my blood. Is there any reason to do it this way, instead of just setting the tile-* values for aom in the crf option processing, the way it's done for rav1e?

break;
}
#endif
} else {
// Set AVOption
Expand Down