Update ffmpeg codec configures

This commit is contained in:
dijunkun
2023-11-08 15:54:08 +08:00
parent 99360f5da2
commit 27bfcb7621
5 changed files with 22 additions and 43 deletions

View File

@@ -47,7 +47,7 @@ FfmpegVideoDecoder::~FfmpegVideoDecoder() {
}
int FfmpegVideoDecoder::Init() {
// av_log_set_level(AV_LOG_DEBUG);
av_log_set_level(AV_LOG_ERROR);
codec_id_ = AV_CODEC_ID_H264;
codec_ = avcodec_find_decoder(codec_id_);
@@ -59,6 +59,8 @@ int FfmpegVideoDecoder::Init() {
if (!codec_ctx_) {
printf("Could not allocate video codec context\n");
return -1;
} else {
LOG_INFO("Use H264 decoder [{}]", codec_->name);
}
codec_ctx_->time_base.num = 1;
@@ -68,8 +70,8 @@ int FfmpegVideoDecoder::Init() {
codec_ctx_->time_base.den = 29;
codec_ctx_->width = 1280;
codec_ctx_->height = 720;
// codec_ctx_->pix_fmt = AV_PIX_FMT_NV12; // yuv420 default?
codec_ctx_->color_range = AVCOL_RANGE_JPEG;
codec_ctx_->pix_fmt = AV_PIX_FMT_YUV420P; // yuv420 default?
codec_ctx_->color_range = AVCOL_RANGE_MPEG;
if (avcodec_open2(codec_ctx_, codec_, NULL) < 0) {
printf("Could not open codec\n");

View File

@@ -59,19 +59,23 @@ FFmpegVideoEncoder::~FFmpegVideoEncoder() {
}
int FFmpegVideoEncoder::Init() {
// av_log_set_level(AV_LOG_VERBOSE);
av_log_set_level(AV_LOG_ERROR);
codec_ = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!codec_) {
LOG_ERROR("Failed to find H.264 encoder");
return -1;
} else {
if (0 == strcmp(codec_->name, "openh264")) {
#ifdef __linux__
if (0 != strcmp(codec_->name, "openh264")) {
use_openh264_ = true;
LOG_INFO("Use H264 encoder [OpenH264]");
}
#else
LOG_INFO("Use H264 encoder [{}]", codec_->name);
#endif
}
use_openh264_ = true;
// use_openh264_ = true;
codec_ctx_ = avcodec_alloc_context3(codec_);
if (!codec_ctx_) {
@@ -93,10 +97,14 @@ int FFmpegVideoEncoder::Init() {
codec_ctx_->gop_size = keyFrameInterval_;
codec_ctx_->keyint_min = keyFrameInterval_;
codec_ctx_->max_b_frames = 0;
codec_ctx_->bit_rate = maxBitrate_ * 2500;
codec_ctx_->bit_rate = maxBitrate_ * 2000;
codec_ctx_->qmin = 15;
codec_ctx_->qmax = 35;
codec_ctx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
codec_ctx_->flags2 |= AV_CODEC_FLAG2_LOCAL_HEADER;
av_opt_set_int(codec_ctx_->priv_data, "qp", 51, 0);
av_opt_set_int(codec_ctx_->priv_data, "crf", 23, 0);
// av_opt_set_int(codec_ctx_->priv_data, "qp", 51, 0);
// av_opt_set_int(codec_ctx_->priv_data, "crf", 23, 0);
if (!use_openh264_) {
av_opt_set(codec_ctx_->priv_data, "profile", "baseline", 0);

View File

@@ -1,31 +0,0 @@
package("openh264")
set_homepage("http://www.openh264.org/")
set_description("OpenH264 is a codec library which supports H.264 encoding and decoding.")
set_license("BSD-2-Clause")
add_urls("https://github.com/cisco/openh264/archive/refs/tags/$(version).tar.gz")
add_versions("v2.3.1", "453afa66dacb560bc5fd0468aabee90c483741571bca820a39a1c07f0362dc32")
add_deps("meson", "ninja", "nasm")
if is_plat("linux") then
add_syslinks("pthread", "rt")
end
on_install("windows", "linux", function (package)
import("package.tools.meson").build(package, {"-Dtests=disabled"}, {buildir = "out"})
import("package.tools.ninja").install(package, {}, {buildir = "out"})
-- if package:config("shared") then
-- os.tryrm(path.join(package:installdir("lib"), "libopenh264.a"))
-- else
-- os.tryrm(path.join(package:installdir("lib"), "libopenh264.so*"))
-- os.tryrm(path.join(package:installdir("lib"), "openh264.lib"))
-- os.tryrm(path.join(package:installdir("bin"), "openh264-*.dll"))
-- end
-- if package:is_plat("windows") then
-- os.trymv(path.join(package:installdir("lib"), "libopenh264.a"), path.join(package:installdir("lib"), "openh264.lib"))
-- end
end)
on_test(function (package)
assert(package:has_cxxfuncs("WelsGetCodecVersion", {includes = "wels/codec_api.h"}))
end)

View File

@@ -1,4 +1,3 @@
includes("openh264")
if is_plat("windows") then
elseif is_plat("linux") then
includes("ffmpeg")

View File

@@ -29,17 +29,18 @@ if is_os("windows") then
add_requires("vcpkg::ffmpeg 5.1.2", {configs = {shared = false}})
add_requires("vcpkg::libnice 0.1.21")
add_packages("vcpkg::libnice")
add_requires("openh264")
add_requires("openh264 2.1.1", {configs = {shared = false}})
elseif is_os("linux") then
add_requireconfs("ffmpeg.x264", {configs = {pic = true}})
add_requires("ffmpeg 5.1.2")
add_requires("glib", {system = true})
add_requires("vcpkg::libnice 0.1.21")
add_requires("openh264")
add_requires("openh264 2.1.1", {configs = {shared = false}})
add_packages("glib", "vcpkg::libnice")
elseif is_os("macosx") then
add_requires("ffmpeg 5.1.2", {system = false})
add_requires("brew::libnice", "brew::glib")
add_requires("openh264 2.1.1", {configs = {shared = false}})
end
add_packages("spdlog")