MCPcopy Create free account
hub / github.com/RGAA-Software/GoDesk / Init

Method Init

src/render/plugins/ffmpeg_encoder/ffmpeg_encoder.cpp:24–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 }
23
24 bool FFmpegEncoder::Init(const EncoderConfig& config, const std::string& monitor_name) {
25 InitLog();
26 encoder_config_ = config;
27 auto encoder_id = config.codec_type == EVideoCodecType::kHEVC ? AV_CODEC_ID_HEVC : AV_CODEC_ID_H264;
28 const char* codec_name = nullptr;
29 if (EVideoCodecType::kHEVC == config.codec_type) {
30 if (EHardwareEncoder::kNvEnc == encoder_config_.Hardware && plugin_->IsHardwareEnabled()) {
31 codec_name = "hevc_nvenc";
32 display_encoder_name_ = "F_NVENC";
33 }
34 // FFmpeg's implementation is so bad.
35 // else if (EHardwareEncoder::kAmf == encoder_config_.Hardware && plugin_->IsHardwareEnabled()) {
36 // codec_name = "hevc_amf";
37 // display_encoder_name_ = "F_AMF";
38 // }
39 else {
40 codec_name = "libx265";
41 display_encoder_name_ = "S/W";
42 }
43 }
44 else if (EVideoCodecType::kH264 == config.codec_type) {
45 if (EHardwareEncoder::kNvEnc == encoder_config_.Hardware && plugin_->IsHardwareEnabled()) {
46 codec_name = "h264_nvenc";
47 display_encoder_name_ = "F_NVENC";
48 }
49 // FFmpeg's implementation is so bad.
50 // else if (EHardwareEncoder::kAmf == encoder_config_.Hardware && plugin_->IsHardwareEnabled()) {
51 // codec_name = "h264_amf";
52 // display_encoder_name_ = "F_AMF";
53 // }
54 else {
55 codec_name = "libx264";
56 display_encoder_name_ = "S/W";
57 }
58 }
59 const AVCodec* encoder = avcodec_find_encoder_by_name(codec_name);
60 if (nullptr == encoder) {
61 LOGE("Could not find encoder for:{}", codec_name);
62 return false;
63 }
64
65 codec_ctx_ = avcodec_alloc_context3(encoder);
66 if (!codec_ctx_) {
67 LOGE("avcodec_alloc_context3 error!");
68 return false;
69 }
70
71 if (encoder_config_.fps <= 0) {
72 encoder_config_.fps = 60;
73 }
74 if (encoder_config_.bitrate < 1000000) {
75 encoder_config_.bitrate = 1000000;
76 }
77
78 codec_ctx_->width = encoder_config_.encode_width;
79 codec_ctx_->height = encoder_config_.encode_height;
80 codec_ctx_->time_base = { 1, encoder_config_.fps };
81 codec_ctx_->framerate = { encoder_config_.fps, 1 };

Callers

nothing calls this directly

Calls 1

IsHardwareEnabledMethod · 0.80

Tested by

no test coverage detected