> 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를 사용한 비디오 처리

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

WebRTC는 워크플로우가 프레임을 처리하는 동안 하나의 세션을 열린 상태로 유지합니다. 이를 통해 추적기, 카운터, 버퍼와 같은 상태 저장 블록을 지원합니다. 또한 각 프레임을 별도의 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>

자체 호스팅의 경우, 다음을 시작하세요 [추론 서버](https://docs.roboflow.com/deployment/self-hosted/inference-server) 클라이언트를 실행하기 전에. 호스팅 제한, 지역, GPU 요금제는 다음을 참조하세요 [Serverless 비디오 스트리밍](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/serverless-video-streaming-api).

## SDK 설치

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

## 워크플로우 스트리밍

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

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

client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY",
)

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` 워크플로우에서 정의한 출력과 일치해야 합니다. 이미지 출력을 비디오로 받으려면 다음에 추가하세요 `stream_output` 그리고 다음을 등록하세요 `on_frame` 핸들러를. 다음을 참조하세요 [WebRTC 스트리밍 참조](https://docs.roboflow.com/reference/inference/inference-sdk/webrtc#stream-a-workflow) 전체 예제를 보려면.

## 비디오 소스 선택

다음을 변경하세요 `소스` 에 전달된 `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) 콜백, 반복자, 세션 정리에 대해.

## 하나의 모델 스트리밍

하나의 모델만 필요할 때는 워크플로우를 만들 필요가 없습니다. 다음을 전달하세요 `model_id` 대신 `워크플로우` 및 `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 비디오 스트리밍](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/serverless-video-streaming-api).
