OBS0.2.4基础框架
+ -

加载用户基本配置信息InitBasicConfig

2024-10-08 10 0
本想着从简单的开始,但是发现核心的渲染如D3D11和新的版本基本差不多,还不如直接用新的代码调试,所以本章节放弃。

InitBasicConfig主要是从basic.ini中读取配置的信息。

bool OBSBasic::InitBasicConfig()
{
    BPtr<char> configPath(os_get_config_path("obs-studio/basic/basic.ini"));

    int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
    if (code != CONFIG_SUCCESS) 
    {
        OBSErrorBox(NULL, "Failed to open basic.ini: %d", code);
        return false;
    }

    return InitBasicConfigDefaults();
}

这些参数通过basicConfig保存,通过InitBasicConfigDefaults()初始化默认参数。

bool OBSBasic::InitBasicConfigDefaults()
{
    bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
    bool hasInputAudio   = HasAudioDevices(App()->InputAudioSource());

    config_set_default_int(basicConfig, "Window", "PosX",  -1);
    config_set_default_int(basicConfig, "Window", "PosY",  -1);
    config_set_default_int(basicConfig, "Window", "SizeX", -1);
    config_set_default_int(basicConfig, "Window", "SizeY", -1);

    vector<MonitorInfo> monitors;
    GetMonitors(monitors);

    if (!monitors.size()) 
    {
        OBSErrorBox(NULL, "There appears to be no monitors.  Er, this ""technically shouldn't be possible.");
        return false;
    }

    uint32_t cx = monitors[0].cx;
    uint32_t cy = monitors[0].cy;

    /* TODO: temporary */
    config_set_default_string(basicConfig, "SimpleOutput", "FilePath",    GetDefaultVideoSavePath().c_str());
    config_set_default_uint  (basicConfig, "SimpleOutput", "VBitrate",    2500);
    config_set_default_uint  (basicConfig, "SimpleOutput", "ABitrate", 128);

    config_set_default_uint  (basicConfig, "Video", "BaseCX",   cx);
    config_set_default_uint  (basicConfig, "Video", "BaseCY",   cy);

    cx = cx * 10 / 15;
    cy = cy * 10 / 15;
    config_set_default_uint  (basicConfig, "Video", "OutputCX", cx);
    config_set_default_uint  (basicConfig, "Video", "OutputCY", cy);

    config_set_default_uint  (basicConfig, "Video", "FPSType", 0);
    config_set_default_string(basicConfig, "Video", "FPSCommon", "30");
    config_set_default_uint  (basicConfig, "Video", "FPSInt", 30);
    config_set_default_uint  (basicConfig, "Video", "FPSNum", 30);
    config_set_default_uint  (basicConfig, "Video", "FPSDen", 1);

    config_set_default_uint  (basicConfig, "Audio", "SampleRate", 44100);
    config_set_default_string(basicConfig, "Audio", "ChannelSetup",    "Stereo");
    config_set_default_uint  (basicConfig, "Audio", "BufferingTime", 1000);

    config_set_default_string(basicConfig, "Audio", "DesktopDevice1",    hasDesktopAudio ? "default" : "disabled");
    config_set_default_string(basicConfig, "Audio", "DesktopDevice2",    "disabled");
    config_set_default_string(basicConfig, "Audio", "AuxDevice1",hasInputAudio ? "default" : "disabled");
    config_set_default_string(basicConfig, "Audio", "AuxDevice2","disabled");
    config_set_default_string(basicConfig, "Audio", "AuxDevice3","disabled");

    return true;
}

一个INI示例文件如下:

[General]
Name=未命名

[Output]
Mode=Simple
FilenameFormatting=%CCYY-%MM-%DD %hh-%mm-%ss
DelayEnable=false
DelaySec=20
DelayPreserve=true
Reconnect=true
RetryDelay=2
MaxRetries=25
BindIP=default
NewSocketLoopEnable=false
LowLatencyEnable=false
IPFamily=IPv4+IPv6

[Stream1]
IgnoreRecommended=false

[SimpleOutput]
FilePath=C:\\Users\\86153\\Videos
RecFormat2=mkv
VBitrate=2500
ABitrate=160
UseAdvanced=false
Preset=veryfast
NVENCPreset2=p5
RecQuality=Stream
RecRB=false
RecRBTime=20
RecRBSize=512
RecRBPrefix=Replay
StreamAudioEncoder=aac
RecAudioEncoder=aac
RecTracks=1
StreamEncoder=x264
RecEncoder=x264
RecFormat=mp4

[AdvOut]
ApplyServiceSettings=true
UseRescale=false
TrackIndex=1
VodTrackIndex=2
Encoder=obs_x264
RecType=Standard
RecFilePath=C:\\Users\\86153\\Videos
RecFormat2=mkv
RecUseRescale=false
RecTracks=1
RecEncoder=none
FLVTrack=1
FFOutputToFile=true
FFFilePath=C:\\Users\\86153\\Videos
FFVBitrate=2500
FFVGOPSize=250
FFUseRescale=false
FFIgnoreCompat=false
FFABitrate=160
FFAudioMixes=1
Track1Bitrate=160
Track2Bitrate=160
Track3Bitrate=160
Track4Bitrate=160
Track5Bitrate=160
Track6Bitrate=160
RecSplitFileTime=15
RecSplitFileSize=2048
RecRB=false
RecRBTime=20
RecRBSize=512
AudioEncoder=ffmpeg_aac
RecAudioEncoder=ffmpeg_aac
RescaleRes=1920x1080
RecRescaleRes=1920x1080
RecSplitFileType=Time
FFFormat=
FFFormatMimeType=
FFRescaleRes=1920x1080
FFVEncoderId=0
FFVEncoder=
FFAEncoderId=0
FFAEncoder=

[Video]
BaseCX=1080
BaseCY=1920
OutputCX=1080
OutputCY=1920
FPSType=0
FPSCommon=30
FPSInt=30
FPSNum=30
FPSDen=1
ScaleType=bicubic
ColorFormat=I420
ColorSpace=709
ColorRange=Partial
SdrWhiteLevel=300
HdrNominalPeakLevel=1000

[Audio]
MonitoringDeviceId=default
MonitoringDeviceName=默认
SampleRate=48000
ChannelSetup=Stereo
MeterDecayRate=23.53
PeakMeterType=0

[Panels]
CookieId=B8A52DDC18217534

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!