> ## Documentation Index
> Fetch the complete documentation index at: https://docs.facebetter.net/llms.txt
> Use this file to discover all available pages before exploring further.

# 뷰티 효과 적용

> Linux에서 C++ API로 Facebetter SDK 2.0을 연동합니다

<Note>
  SDK **2.0.0**. Windows와 동일한 C++ API(`facebetter` 네임스페이스). 열거형: [파라미터 열거형](/ko/intro/makeup). 인증: [인증 및 라이선스](/ko/intro/license).
</Note>

Linux에서 Facebetter는 `libfacebetter.so`와 `facebetter/*.h`입니다. 이 가이드는 [C++ 데스크톱 데모](https://github.com/pixpark/facebetter-sdk)(`demo/cpp`)를 따릅니다. SDK 자체를 컴파일하려면 `./scripts/build_linux.sh` 또는 `build/linux`에서 CMake를 사용하세요.

## 헤더 포함

```cpp theme={null}
#include <facebetter/beauty_effect_engine.h>
#include <facebetter/beauty_params.h>
#include <facebetter/image_frame.h>
#include <facebetter/type_defines.h>

using namespace facebetter;
using namespace facebetter::beauty_params;
```

## CMake 링크

```cmake theme={null}
target_include_directories(your_target PRIVATE /path/to/sdk/include)
target_link_libraries(your_target PRIVATE
    /path/to/sdk/lib/libfacebetter.so
    GL
)
```

런타임에 `LD_LIBRARY_PATH`를 설정하거나, `libfacebetter.so`를 바이너리 옆으로 복사하거나, `ldconfig`로 설치하세요.

## 연동 흐름

```
SetLogConfig → Create(EngineConfig) → set effects → ProcessImage → render
```

타입 활성화 단계는 없습니다. 강도 `0`이면 효과가 꺼집니다.

***

## 1. 로그 설정 (선택)

`Create` **전에** 호출하세요.

```cpp theme={null}
LogConfig log_cfg;
log_cfg.console_enabled = true;
log_cfg.file_enabled = false;
log_cfg.level = LogLevel::Info;
BeautyEffectEngine::SetLogConfig(log_cfg);
```

***

## 2. 엔진 만들기

데스크톱은 `resource_path`를 `resource.fbd` **파일**로 설정해야 **합니다**.

**인증 우선순위:** 비어 있지 않은 `license_token`(토큰 / `{token}` JSON / `.lic`)이 우선합니다. 그렇지 않으면 `app_id` + `app_key` 온라인 v2입니다.

```cpp theme={null}
EngineConfig cfg;
cfg.app_id = "your_app_id";
cfg.app_key = "your_app_key";
cfg.resource_path = "resource/resource.fbd";  // path to the .fbd file
cfg.external_context = false;

// cfg.license_token = "/* license token, {token} JSON, or .lic contents */";

auto engine = BeautyEffectEngine::Create(cfg);
if (!engine) {
    return -1;
}
```

<Warning>
  `resource_path`는 폴더가 아니라 `resource.fbd` 파일이어야 합니다. 프로덕션에서는 절대 경로를 권장합니다.
</Warning>

***

## 3. 뷰티 파라미터 설정

피부 / 메이크업 / 바디 리셰이프 `[0.0, 1.0]`. 페이스 리셰이프 **`[-1.0, 1.0]`**. 바디 리셰이프에는 `resource_body.fbd`가 필요합니다. [파라미터 열거형](/ko/intro/makeup), [선택 리소스 팩](/ko/intro/resource-packs).

```cpp theme={null}
engine->SetSmoothing(0.5f);
engine->SetSmoothingStyle(SmoothingStyle::Natural);
engine->SetWhitening(0.3f);
engine->SetWhiteningStyle(WhiteningStyle::ColdWhite);
engine->SetSharpening(0.2f);
engine->SetRosiness(0.2f);
engine->SetBeautySkinOnly(true);

engine->SetReshape(Reshape::FaceThin, 0.4f);
engine->SetReshape(Reshape::EyeSize, 0.3f);

engine->AddResourcePack("resource/resource_body.fbd");  // or place resource_body.fbd next to resource.fbd
engine->SetBodyReshape(BodyReshape::WaistSlim, 0.4f);
engine->SetBodyReshape(BodyReshape::LegStretch, 0.3f);
engine->SetBodyReshape(BodyReshape::TorsoLong, 0.3f);

engine->SetLipstick(0.6f);
engine->SetLipstickColor(LipstickColor::Rouge);
engine->SetBlush(0.4f);
engine->SetBlushStyle(BlushStyle::SunKissed);
engine->SetBlushColor(BlushColor::CoralPink);
engine->SetContour(0.5f);
engine->SetContourStyle(ContourStyle::Natural);
```

아이섀도, 아이라이너, 눈썹, 속눈썹, 렌즈도 같은 패턴입니다.

***

## 4. 필터, 스티커, 가상 배경

**경로** 또는 **바이트**를 전달하세요.

```cpp theme={null}
engine->SetFilter("assets/filters/natural.fbd");
engine->SetFilterIntensity(0.8f);
engine->ClearFilter();

engine->SetSticker("assets/stickers/face/black_glass.fbd");
engine->ClearSticker();

engine->AddResourcePack("resource/resource_3d.fbd");  // or place it next to resource.fbd
engine->Set3DSticker("assets/stickers/3d/oculos.fbd");
engine->Clear3DSticker();

engine->SetVirtualBackgroundBlur(0.6f);
engine->SetVirtualBackground("assets/background.jpg");
engine->ClearVirtualBackground();

engine->SetChromaKey(ChromaKeyColor::Green);
engine->SetChromaKeySimilarity(0.4f);
engine->ClearChromaKey();
```

***

## 5. 콜백과 통계

```cpp theme={null}
EngineCallbacks cbs;
cbs.on_engine_event = [](int code, const std::string& message) {
    // 0 license OK, 1 failed, 100 init complete, 101 init failed
    printf("[event] %d %s\n", code, message.c_str());
};
cbs.on_face_landmarks = [](const std::vector<FaceDetectionResult>& faces) {
    printf("faces=%zu\n", faces.size());
};
engine->SetCallbacks(cbs);

EngineStats stats = engine->GetStats();
```

***

## 6. 프레임 처리

`ImageFrame::type`을 설정하세요.

```cpp theme={null}
auto input = ImageFrame::CreateWithRGBA(rgba_data, width, height, stride);
input->type = FrameType::Video;
auto output = engine->ProcessImage(input);
```

사진:

```cpp theme={null}
auto input = ImageFrame::CreateWithFile("input.jpg");
input->type = FrameType::Image;
auto output = engine->ProcessImage(input);
output->ToFile("output.jpg", 95);
```

<Tip>
  출력 형식은 가능하면 입력을 따릅니다. `output->Convert(Format::BGRA)`로 변환하세요.
</Tip>

### OpenGL 미리보기

```cpp theme={null}
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
             output->Width(), output->Height(),
             0, GL_RGBA, GL_UNSIGNED_BYTE, output->Data());
```

앱에 이미 현재 GL 컨텍스트가 있으면 `cfg.external_context = true`를 설정하고 해당 스레드에서 `ProcessImage`를 호출하세요.

***

## 7. 최소 루프

```cpp theme={null}
LogConfig log_cfg;
log_cfg.console_enabled = true;
log_cfg.level = LogLevel::Info;
BeautyEffectEngine::SetLogConfig(log_cfg);

EngineConfig cfg;
cfg.app_id = "your_app_id";
cfg.app_key = "your_app_key";
cfg.resource_path = "resource/resource.fbd";
auto engine = BeautyEffectEngine::Create(cfg);
if (!engine) return -1;

engine->SetSmoothing(0.5f);
engine->SetReshape(Reshape::FaceThin, 0.3f);
engine->SetLipstick(0.5f);

auto input = ImageFrame::CreateWithRGBA(rgba, width, height, stride);
input->type = FrameType::Video;
auto output = engine->ProcessImage(input);
```

`engine.reset()`으로 해제하세요. 엔진은 싱글톤이 **아닙니다**.

TRTC / Agora / LiveKit: [서드파티 연동](/ko/linux/third-party-integration).

## 관련 문서

<CardGroup cols={2}>
  <Card title="서드파티 연동" href="/ko/linux/third-party-integration">TRTC / Agora / LiveKit</Card>
  <Card title="API 레퍼런스" href="/ko/linux/api-reference">C++ 메서드와 Linux 참고 사항</Card>
  <Card title="오류 처리" href="/ko/linux/error-handling">반환 코드와 .so / DISPLAY 문제</Card>
  <Card title="권장 사항" href="/ko/linux/best-practices">성능과 rpath</Card>
</CardGroup>
