> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/workflows/ko/deploy/video-processing.md).

# Workflows로 비디오 처리

Workflow를 통해 비디오를 스트리밍하려면 Inference SDK WebRTC 클라이언트를 사용하세요. 동일한 클라이언트는 자체 호스팅 Inference Server와 Serverless Video Streaming API에서도 작동합니다.

WebRTC는 Workflow가 프레임을 처리하는 동안 하나의 세션을 계속 열어 둡니다. 이를 통해 추적기, 카운터, 버퍼와 같은 상태 저장 블록을 지원합니다. 또한 각 프레임을 별도의 HTTP 요청으로 보내는 것을 방지합니다.

## 런타임 선택

<table data-search="false"><thead><tr><th>런타임</th><th>API URL</th><th>다음과 같은 경우 사용</th></tr></thead><tbody><tr><td>자체 호스팅 Inference Server</td><td><code>http://localhost:9001</code></td><td>비디오를 자신의 하드웨어나 네트워크에 유지하고 싶을 때.</td></tr><tr><td>Serverless Video Streaming API</td><td><code>https://serverless.roboflow.com</code></td><td>Roboflow가 컴퓨팅을 관리하도록 하고 싶을 때.</td></tr></tbody></table>

자체 호스팅을 사용하는 경우, 클라이언트를 실행하기 전에 [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) 를 시작하세요. 호스팅 제한, 리전, GPU 플랜은 다음을 참조하세요. [Serverless Video Streaming](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/serverless-video-streaming-api).

## SDK 설치

```bash
pip install "inference-sdk[webrtc]"
```

## Workflow 스트리밍

이 예제는 웹캠에서 비디오를 캡처하고 저장된 Workflow의 `예측` 출력을 출력합니다:

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration
from inference_sdk.webrtc import StreamConfig, WebcamSource

client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY",
).configure(InferenceConfiguration(api_key_transport="header"))

session = client.webrtc.stream(
    source=WebcamSource(),
    workflow="workflow-id",
    workspace="workspace-name",
    config=StreamConfig(data_output=["predictions"]),
)

@session.on_data("predictions")
def handle_predictions(predictions, metadata):
    print(f"Frame {metadata.frame_id}: {predictions}")

session.run()
```

다음을 `workflow-id`, `workspace-name`, 및 `ROBOFLOW_API_KEY` 를 자신의 값으로 바꾸세요. Serverless에서 실행하려면 `api_url` 을 `https://serverless.roboflow.com`.

다음의 이름은 `data_output` Workflow에서 정의된 출력과 일치해야 합니다. 이미지 출력을 비디오로 받으려면 이를 `stream_output` 에 추가하고 `on_frame` 핸들러를 등록하세요. 전체 예시는 다음을 참조하세요. [WebRTC 스트리밍 참고 문서](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#stream-a-workflow) 에서 확인하세요.

## 비디오 소스 선택

다음을 변경하세요. `source` 를 `client.webrtc.stream()` 에 전달할 때 비디오가 어디에서 오는지에 따라 다음과 같이 설정하세요:

<table data-search="false"><thead><tr><th>소스</th><th>다음과 같은 경우 사용</th></tr></thead><tbody><tr><td><code>WebcamSource()</code></td><td>카메라가 클라이언트 머신에 연결되어 있습니다.</td></tr><tr><td><code>RTSPSource("rtsp://...")</code></td><td>Inference Server가 RTSP 카메라에 접근할 수 있습니다.</td></tr><tr><td><code>LocalStreamSource("rtsp://...")</code></td><td>클라이언트만 RTSP 또는 RTMP 스트림에 접근할 수 있습니다.</td></tr><tr><td><code>VideoFileSource("video.mp4")</code></td><td>저장된 비디오 파일을 처리하고 싶을 때.</td></tr><tr><td><code>ManualSource()</code></td><td>애플리케이션이 개별 프레임을 제공합니다.</td></tr></tbody></table>

다음을 사용할 때 `RTSPSource` 를 Serverless와 함께 사용하면 카메라 URL은 공용 인터넷에서 접근 가능해야 합니다. 카메라가 클라이언트 네트워크에서만 사용 가능한 경우에는 `LocalStreamSource` 를 사용하세요.

다음을 참조하세요. [WebRTC 비디오 소스](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#video-sources) 에서 소스 구성 및 [결과 소비](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#consuming-results) 에서 콜백, 이터레이터, 세션 정리를 확인하세요.

## 하나의 모델 스트리밍

하나의 모델만 필요할 때는 Workflow를 만들 필요가 없습니다. 대신 `model_id` 를 사용하고 `workflow` 와 `workspace`:

```python
session = client.webrtc.stream(
    source=WebcamSource(),
    model_id="rfdetr-nano",
)
```

다음을 참조하세요. [모델 스트리밍](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#stream-a-model) 는 작업 유형에 따라 예측 처리를 수행합니다.

## 다음 단계

* 다음에서 프레임 및 데이터 출력을 구성하세요. [WebRTC 스트리밍 참고 문서](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc).
* 다음을 시작하고 구성하세요. [자체 호스팅 Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server).
* 다음에서 호스팅 리전, 플랜, 제한을 검토하세요. [Serverless Video Streaming](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/serverless-video-streaming-api).
