Commit 8f056840 authored by zhyh2010's avatar zhyh2010
Browse files

增加sample简单用例

parent 0cb40ca1
Decode,Bit Depth,Resolution,Fps/(BMZ 1 Core),Fps/(BMZ 6 Processes) Decode,Bit Depth,Resolution,Fps/(BMZ 1 Core),Fps/(BMZ 6 Processes)
H264,8,1920x1080,506.87,2277.36 H264,8,1920x1080,499.38,2056.14
Encode,Bit Depth,Resolution,Fps/(BMZ 1 Core) Encode,Bit Depth,Resolution,Fps/(BMZ 1 Core)
H264,8,1920x1080,251.78 H264,8,1920x1080,230.31
# FFmpeg DCU python测试用例
这是一个简单的 DCU视频编解码Python demo用例。
## 环境要求
- **驱动**: 与MacCodecSDK版本一致
### 软件
- **FFmpeg**:
- `MacCodecSDK`
- **Python 依赖**:
- `ffmpeg-python`
- **docker环境**:
- `基于DTK2504镜像即可,本sample使用harbor.sourcefind.cn:5443/dcu/admin/base/vllm:0.9.2-ubuntu22.04-dtk26.04-0130-py3.10-20260202`
## 安装步骤
### 1. 安装系统级 MacCodecSDK
确保 FFmpeg 已安装,可通过ffmpeg指令验证
### 2. 安装 Python 依赖
```bash
pip install ffmpeg-python
```
## 使用方法
运行脚本:
```bash
python benchmark_cuda.py
```
## 输出示例
### 成功情况
```text
--- Starting CUDA Benchmark for ./sample_1920x1080_30fps_8bit.h264 ---
[1] Testing CUDA Decode...
Decode Success
[2] Testing CUDA Encode (H264 NVENC)...
Encode Success
--- Benchmark Finished ---
```
\ No newline at end of file
#!/usr/bin/env python3
import ffmpeg
import subprocess
import sys
import os
import re
def run_ffmpeg_command(cmd):
"""运行命令并返回 stderr 日志"""
try:
result = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True)
return result.stderr
except Exception as e:
return f"Error: {e}"
def main():
input_file = "./sample_1920x1080_30fps_8bit.h264"
if not os.path.exists(input_file):
print(f"Error: File {input_file} not found")
sys.exit(1)
print(f"--- Starting CUDA Benchmark for {input_file} ---\n")
# 1. CUDA 解码测试 (hwaccel cuda)
print("[1] Testing CUDA Decode...")
try:
stream = ffmpeg.input(input_file, hwaccel='cuda')
cmd = ffmpeg.output(stream, 'pipe:', format='null').global_args('-benchmark', '-y').compile()
log_content = run_ffmpeg_command(cmd)
print(f" Decode Success\n")
except Exception as e:
print(f" Decode Failed: {e}\n")
# 2. CUDA 编码测试 (h264_nvenc)
print("[2] Testing CUDA Encode (H264 NVENC)...")
output_file = "output_cuda_temp.mp4"
try:
stream = ffmpeg.input(input_file)
cmd = ffmpeg.output(stream, output_file, vcodec='h264_nvenc').global_args('-benchmark', '-y').compile()
log_content = run_ffmpeg_command(cmd)
print(f" Encode Success\n")
except Exception as e:
print(f" Encode Failed: {e}\n")
finally:
# 清理临时文件
if os.path.exists(output_file):
os.remove(output_file)
print("--- Benchmark Finished ---")
if __name__ == "__main__":
main()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment