# MPEG-2 TS

v0.10.4 버전부터 MPEG-2 TS 입력이 지원됩니다. 지원되는 코덱은 H.264, AAC(ADTS)이며, 향후 더 많은 코덱이 추가될 예정입니다. 또한 현재 버전은 188바이트 패킷 크기를 사용하는 기본적인 MPEG-2 TS만 지원합니다. 입력 스트림에 대한 정보는 `PAT` 및 `PMT`를 통해 획득되므로, 클라이언트는 반드시 이 테이블 정보를 전송해야 합니다.

<table><thead><tr><th width="216.666748046875">Item</th><th>Description</th></tr></thead><tbody><tr><td>Container</td><td>MPEG-2 TS</td></tr><tr><td>Transport</td><td>UDT / TCP</td></tr><tr><td>Codec</td><td>H.264, H.265, AAC</td></tr></tbody></table>

## Configuration

MPEG-2 TS를 사용하려면 먼저 포트를 바인딩하고, 바인딩된 포트와 스트림을 매핑해야 합니다.

### Bind

여러 스트림을 사용하려면 여러 포트를 바인딩해야 합니다. 아래 예제와 같이 여러 포트를 바인딩할 수 있으며, `Start port-End port` 형식으로 범위를 지정하거나 콤마(`,`)로 여러 포트를 지정할 수 있습니다.

### Stream mapping

먼저 스트림 이름을 지정하고, 위에서 바인딩한 포트와 매핑해야 합니다. 여러 스트림을 한 번에 매핑하기 위해 `${Port}` 매크로가 제공됩니다. 아래 예제를 참고하시기 바랍니다.

{% code overflow="wrap" %}

```xml
<!-- /Server/Bind -->
<Providers>
    ...
    <MPEGTS>
        <!--
            Listen on port 4000,4001,4004,4005
            This is just a demonstration to show that
            you can configure the port in several ways
        -->
        <Port>4000-4001,4004,4005/udp</Port>
        ...
    </MPEGTS>
</providers>

<!-- /Server/VirtualHosts/VirtualHost/Applications/Application -->
<Providers>
    ...
    <MPEGTS>
        <StreamMap>
            <!--
                Set the stream name of the client connected to the
                port to "stream_${Port}"
                For example, if a client connets to port 4000,
                OME creates a "stream_4000" stream
            -->
            <Stream>
                <Name>stream_${Port}</Name>
                <Port>4000-4001,4004</Port>
            </Stream>
            <Stream>
                <Name>stream_name_for_4005_port</Name>
                <Port>4005</Port>
            </Stream>
            ...
        </StreamMap>
    </MPEGTS>
</Providers>
```

{% endcode %}

## Publish

다음은 FFmpeg를 사용하여 퍼블리시하는 예제입니다.

{% code overflow="wrap" %}

```markup
# Video / Audio
ffmpeg.exe -re -stream_loop -1 -i <file.ext> -c:v libx264 -bf 0 -x264-params keyint=30:scenecut=0  -acodec aac -pes_payload_size 0 -f mpegts udp://<IP>:4000?pkt_size=1316

# Video only
ffmpeg.exe -re -stream_loop -1 -i <file.ext> -c:v libx264 -bf 0 -x264-params keyint=30:scenecut=0  -an -f mpegts udp://<IP>:4000?pkt_size=1316

# Audio only
ffmpeg.exe -re -stream_loop -1 -i <file.ext> -vn  -acodec aac -pes_payload_size 0 -f mpegts udp://<IP>:4000?pkt_size=1316
```

{% endcode %}

{% hint style="info" %}
AAC 코덱에 `-pes_payload_size 0` 옵션을 지정하는 것은 AV 동기화 및 저지연을 위해 매우 중요합니다. 이 옵션을 지정하지 않으면 FFmpeg가 여러 개의 ADTS를 묶어서 한 번에 전송하게 되어, 지연이 증가하거나 AV 동기화 문제가 발생할 수 있습니다.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ovenmediaengine-enterprise.gitbook.io/guide/ko-kr/features/live-source/mpeg-2-ts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
