# Video Demo

## Overview

This example demonstrates how to use the K230 video encode/decode modules (`VENC`/`VDEC`) to perform video encoding and decoding.

## Functional Description

### VENC Features

The video encoder path provides:

- support for formats such as H.264 and H.265
- configurable output resolution
- bitrate control modes such as CBR and VBR
- configurable output frame rate
- GOP size configuration

### VDEC Features

The video decoder path provides:

- support for formats such as H.264 and H.265
- hardware-accelerated decoding
- multi-stream decode capability
- direct output to VO display

## Source Location

Demo source path: `src/rtsmart/examples/mpp/sample_venc`

## Usage

### Build

At the root of `K230 RTOS SDK`, use `make menuconfig` to enable the Video example in the firmware build, then build the firmware.

### Run

```shell
./sample_venc.elf [options]
```

### Parameters

| Parameter | Description | Default |
| --- | --- | --- |
| codec type | `h264` / `h265` | `h265` |
| width | image width | `1920` |
| height | image height | `1080` |
| frame rate | output frame rate | `30` |
| bitrate | encoding bitrate | `4000` |

### Expected Result

After the program starts, it will:

1. initialize the video encoder
1. configure the encoding parameters
1. start the encoding loop
1. output the encoded bitstream

Example output:

```text
Video Encoder Demo
=================

Initializing VENC module...
VENC initialized successfully

Configuring encoder...
Codec: H.265
Resolution: 1920x1080
Frame rate: 30fps
Bitrate: 4000Kbps

Starting encoding...
Encoding frames...
Frame 1 encoded
Frame 2 encoded
Frame 3 encoded
...

Encoding statistics:
Total frames: 1000
Total bytes: 52428800
Bitrate: 4000Kbps (actual)

Press Ctrl+C to stop.
```

```{admonition} Tip
Video encode/decode is one of the core parts of the media stack. Choose encoding parameters according to the actual application scenario. For detailed interfaces, refer to the [Video Encoder/Decoder API documentation](../../api_reference/mpp/video.md).
```
