mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Set I frame max qp to 22 for nvidia encoder
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define SAVE_DECODER_STREAM 1
|
#define SAVE_DECODER_STREAM 0
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define SAVE_DECODER_STREAM 1
|
#define SAVE_DECODER_STREAM 0
|
||||||
|
|
||||||
NvidiaVideoDecoder::NvidiaVideoDecoder() {}
|
NvidiaVideoDecoder::NvidiaVideoDecoder() {}
|
||||||
NvidiaVideoDecoder::~NvidiaVideoDecoder() {
|
NvidiaVideoDecoder::~NvidiaVideoDecoder() {
|
||||||
@@ -51,7 +51,7 @@ int NvidiaVideoDecoder::Decode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((*(data + 4) & 0x1f) == 0x07) {
|
if ((*(data + 4) & 0x1f) == 0x07) {
|
||||||
// LOG_WARN("Receive key frame");
|
LOG_WARN("Receive key frame");
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_frame_returned = decoder->Decode(data, size);
|
int num_frame_returned = decoder->Decode(data, size);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "video_decoder_factory.h"
|
#include "video_decoder_factory.h"
|
||||||
|
|
||||||
#include "ffmpeg/ffmpeg_video_decoder.h"
|
#include "ffmpeg/ffmpeg_video_decoder.h"
|
||||||
|
#include "log.h"
|
||||||
#include "nvcodec/nvidia_video_decoder.h"
|
#include "nvcodec/nvidia_video_decoder.h"
|
||||||
|
|
||||||
VideoDecoderFactory::VideoDecoderFactory() {}
|
VideoDecoderFactory::VideoDecoderFactory() {}
|
||||||
@@ -26,6 +27,9 @@ bool VideoDecoderFactory::CheckIsHardwareAccerlerationSupported() {
|
|||||||
CUvideoctxlock cudaCtxLock;
|
CUvideoctxlock cudaCtxLock;
|
||||||
cuResult = cuvidCtxLockCreate(&cudaCtxLock, 0);
|
cuResult = cuvidCtxLockCreate(&cudaCtxLock, 0);
|
||||||
if (cuResult != CUDA_SUCCESS) {
|
if (cuResult != CUDA_SUCCESS) {
|
||||||
|
LOG_WARN(
|
||||||
|
"System not support hardware accelerated decode, use default software "
|
||||||
|
"decoder");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define SAVE_ENCODER_STREAM 1
|
#define SAVE_ENCODER_STREAM 0
|
||||||
|
|
||||||
FFmpegVideoEncoder::FFmpegVideoEncoder() {}
|
FFmpegVideoEncoder::FFmpegVideoEncoder() {}
|
||||||
FFmpegVideoEncoder::~FFmpegVideoEncoder() {
|
FFmpegVideoEncoder::~FFmpegVideoEncoder() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define SAVE_ENCODER_STREAM 1
|
#define SAVE_ENCODER_STREAM 0
|
||||||
|
|
||||||
NvidiaVideoEncoder::NvidiaVideoEncoder() {}
|
NvidiaVideoEncoder::NvidiaVideoEncoder() {}
|
||||||
NvidiaVideoEncoder::~NvidiaVideoEncoder() {
|
NvidiaVideoEncoder::~NvidiaVideoEncoder() {
|
||||||
@@ -50,14 +50,15 @@ int NvidiaVideoEncoder::Init() {
|
|||||||
init_params.encodeConfig->profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
|
init_params.encodeConfig->profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
|
||||||
init_params.encodeConfig->encodeCodecConfig.h264Config.level =
|
init_params.encodeConfig->encodeCodecConfig.h264Config.level =
|
||||||
NV_ENC_LEVEL::NV_ENC_LEVEL_H264_31;
|
NV_ENC_LEVEL::NV_ENC_LEVEL_H264_31;
|
||||||
// TO TEST: not tested yet
|
|
||||||
// init_params.encodeConfig->gopLength = NVENC_INFINITE_GOPLENGTH;
|
|
||||||
init_params.encodeConfig->gopLength = keyFrameInterval_;
|
init_params.encodeConfig->gopLength = keyFrameInterval_;
|
||||||
// Do not use B-frame for realtime application
|
|
||||||
init_params.encodeConfig->frameIntervalP = 1;
|
init_params.encodeConfig->frameIntervalP = 1;
|
||||||
init_params.encodeConfig->rcParams.rateControlMode =
|
init_params.encodeConfig->rcParams.rateControlMode =
|
||||||
NV_ENC_PARAMS_RC_MODE::NV_ENC_PARAMS_RC_CBR;
|
NV_ENC_PARAMS_RC_MODE::NV_ENC_PARAMS_RC_VBR;
|
||||||
init_params.encodeConfig->rcParams.maxBitRate = maxBitrate_ * 500;
|
init_params.encodeConfig->rcParams.maxBitRate = maxBitrate_ * 500;
|
||||||
|
// init_params.encodeConfig->rcParams.enableMinQP = 1;
|
||||||
|
// init_params.encodeConfig->rcParams.minQP.qpIntra = 10;
|
||||||
|
init_params.encodeConfig->rcParams.enableMaxQP = 1;
|
||||||
|
init_params.encodeConfig->rcParams.maxQP.qpIntra = 22;
|
||||||
init_params.encodeConfig->encodeCodecConfig.h264Config.sliceMode = 1;
|
init_params.encodeConfig->encodeCodecConfig.h264Config.sliceMode = 1;
|
||||||
init_params.encodeConfig->encodeCodecConfig.h264Config.sliceModeData =
|
init_params.encodeConfig->encodeCodecConfig.h264Config.sliceModeData =
|
||||||
max_payload_size_;
|
max_payload_size_;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "video_encoder_factory.h"
|
#include "video_encoder_factory.h"
|
||||||
|
|
||||||
#include "ffmpeg/ffmpeg_video_encoder.h"
|
#include "ffmpeg/ffmpeg_video_encoder.h"
|
||||||
|
#include "log.h"
|
||||||
#include "nvcodec/nvidia_video_encoder.h"
|
#include "nvcodec/nvidia_video_encoder.h"
|
||||||
|
|
||||||
VideoEncoderFactory::VideoEncoderFactory() {}
|
VideoEncoderFactory::VideoEncoderFactory() {}
|
||||||
@@ -26,11 +27,17 @@ bool VideoEncoderFactory::CheckIsHardwareAccerlerationSupported() {
|
|||||||
|
|
||||||
cuResult = cuInit(0);
|
cuResult = cuInit(0);
|
||||||
if (cuResult != CUDA_SUCCESS) {
|
if (cuResult != CUDA_SUCCESS) {
|
||||||
|
LOG_WARN(
|
||||||
|
"System not support hardware accelerated encode, use default software "
|
||||||
|
"encoder");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NVENCSTATUS nvEncStatus = NvEncodeAPICreateInstance(&functionList);
|
NVENCSTATUS nvEncStatus = NvEncodeAPICreateInstance(&functionList);
|
||||||
if (nvEncStatus != NV_ENC_SUCCESS) {
|
if (nvEncStatus != NV_ENC_SUCCESS) {
|
||||||
|
LOG_WARN(
|
||||||
|
"System not support hardware accelerated encode, use default software "
|
||||||
|
"encoder");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,17 +119,33 @@ int PeerConnection::Init(PeerConnectionParams params,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::CreateVideoCodec(bool hardware_acceleration) {
|
int PeerConnection::CreateVideoCodec(bool hardware_acceleration) {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
if (hardware_acceleration) {
|
||||||
|
hardware_acceleration = false;
|
||||||
|
LOG_WARN(
|
||||||
|
"MacOS not support hardware acceleration, use default software codec");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
|
||||||
video_encoder_ =
|
video_encoder_ =
|
||||||
VideoEncoderFactory::CreateVideoEncoder(hardware_acceleration_);
|
VideoEncoderFactory::CreateVideoEncoder(hardware_acceleration_);
|
||||||
if (hardware_acceleration_ && !video_encoder_) {
|
if (hardware_acceleration_ && !video_encoder_) {
|
||||||
|
LOG_WARN(
|
||||||
|
"Hardware accelerated encoder not available, use default software "
|
||||||
|
"encoder");
|
||||||
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
||||||
if (!video_encoder_) {
|
if (!video_encoder_) {
|
||||||
|
LOG_ERROR(
|
||||||
|
"Hardware accelerated encoder and software encoder both not "
|
||||||
|
"available");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 != video_encoder_->Init()) {
|
if (0 != video_encoder_->Init()) {
|
||||||
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
video_encoder_ = VideoEncoderFactory::CreateVideoEncoder(false);
|
||||||
if (!video_encoder_ || 0 != video_encoder_->Init()) {
|
if (!video_encoder_ || 0 != video_encoder_->Init()) {
|
||||||
|
LOG_ERROR("Encoder init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,14 +153,21 @@ int PeerConnection::CreateVideoCodec(bool hardware_acceleration) {
|
|||||||
video_decoder_ =
|
video_decoder_ =
|
||||||
VideoDecoderFactory::CreateVideoDecoder(hardware_acceleration_);
|
VideoDecoderFactory::CreateVideoDecoder(hardware_acceleration_);
|
||||||
if (hardware_acceleration_ && !video_decoder_) {
|
if (hardware_acceleration_ && !video_decoder_) {
|
||||||
|
LOG_WARN(
|
||||||
|
"Hardware accelerated decoder not available, use default software "
|
||||||
|
"decoder");
|
||||||
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
||||||
if (!video_decoder_) {
|
if (!video_decoder_) {
|
||||||
|
LOG_ERROR(
|
||||||
|
"Hardware accelerated decoder and software decoder both not "
|
||||||
|
"available");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 != video_decoder_->Init()) {
|
if (0 != video_decoder_->Init()) {
|
||||||
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
video_decoder_ = VideoDecoderFactory::CreateVideoDecoder(false);
|
||||||
if (!video_decoder_ || video_decoder_->Init()) {
|
if (!video_decoder_ || video_decoder_->Init()) {
|
||||||
|
LOG_ERROR("Decoder init failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user