feat: add NVENC multi-session test script and documentation

This commit is contained in:
kimasplund 2025-02-11 12:37:16 +02:00
commit 9d3794b9b5
2 changed files with 204 additions and 0 deletions

View file

@ -0,0 +1,106 @@
# NVENC Multi-Session Test Script
This script demonstrates and tests NVIDIA NVENC hardware encoding capabilities with the NVENC patch. It allows running multiple simultaneous encoding sessions, beyond the default limit of 2 sessions on consumer GPUs.
## Features
- Test multiple simultaneous NVENC encoding sessions
- Support for H.264, HEVC (H.265), and AV1 NVENC encoders
- Configurable encoding parameters (resolution, bitrate, framerate, etc.)
- Detailed performance metrics for each session
- Session statistics reporting (file size and encoding speed)
## Requirements
- NVIDIA GPU with NVENC support
- NVIDIA drivers with NVENC patch applied
- FFmpeg compiled with NVENC support
- Linux operating system
## Usage
```bash
./test_nvenc.sh [OPTIONS]
```
### Options
- `-n NUMBER` : Number of simultaneous sessions (default: 8)
- `-d DURATION` : Test duration in seconds (default: 10)
- `-r RES` : Resolution in WxH format (default: 1920x1080)
- `-f FPS` : Framerate (default: 30)
- `-b BITRATE` : Target bitrate (default: 5M)
- `-p PRESET` : NVENC preset p1-p7 (default: p7)
- `-c CODEC` : Encoder codec (h264_nvenc, hevc_nvenc, av1_nvenc) (default: h264_nvenc)
- `-h` : Display help message
### Examples
1. Basic test with default settings:
```bash
./test_nvenc.sh
```
2. Test 12 simultaneous H.264 sessions:
```bash
./test_nvenc.sh -n 12
```
3. Test HEVC encoding with custom parameters:
```bash
./test_nvenc.sh -c hevc_nvenc -r 3840x2160 -b 20M -p p7
```
4. Test AV1 encoding:
```bash
./test_nvenc.sh -c av1_nvenc -n 4
```
## Output
The script generates:
1. Encoded video files (`output_1.mp4`, `output_2.mp4`, etc.)
2. Session log files with detailed encoding statistics (`session_1.log`, `session_2.log`, etc.)
3. Summary of encoding statistics including file sizes and encoding speeds
## Performance Metrics
The script reports two key metrics for each session:
1. Output file size
2. Encoding speed (relative to real-time, e.g., 6.5x means 6.5 times faster than real-time)
## Notes
1. Without the NVENC patch, consumer NVIDIA GPUs are limited to 2 simultaneous encoding sessions.
2. The actual number of possible simultaneous sessions depends on:
- GPU model and capabilities
- Available GPU memory
- Encoding parameters (resolution, bitrate, etc.)
- System resources
3. Performance considerations:
- Encoding speed typically decreases as the number of simultaneous sessions increases
- The p7 preset provides the best quality but slowest encoding speed
- p1 preset offers the fastest encoding with lower quality
- Higher resolutions and bitrates require more GPU resources
## Troubleshooting
1. If sessions fail to start, check:
- NVIDIA driver installation
- NVENC patch status
- FFmpeg NVENC support
- GPU resource usage
2. If performance is poor, try:
- Reducing the number of simultaneous sessions
- Using a faster preset (p1-p3)
- Lowering resolution or bitrate
- Checking GPU temperature and utilization
## Cleanup
To remove all test files:
```bash
rm -f output_*.mp4 session_*.log
```

View file

@ -0,0 +1,98 @@
#!/bin/bash
# NVENC Multi-Session Test Script
# This script tests NVIDIA NVENC hardware encoding capabilities by running multiple simultaneous encoding sessions.
# It demonstrates the removal of the 2-session limit on consumer GPUs through the NVENC patch.
# Default settings
DURATION=10
RESOLUTION="1920x1080"
FRAMERATE=30
BITRATE="5M"
NUM_SESSIONS=8
PRESET="p7" # p1 (fastest) to p7 (slowest)
CODEC="h264_nvenc" # can be h264_nvenc, hevc_nvenc, or av1_nvenc
# Function to display script usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -n NUMBER Number of simultaneous sessions (default: 8)"
echo " -d DURATION Test duration in seconds (default: 10)"
echo " -r RES Resolution in WxH format (default: 1920x1080)"
echo " -f FPS Framerate (default: 30)"
echo " -b BITRATE Target bitrate (default: 5M)"
echo " -p PRESET NVENC preset p1-p7 (default: p7)"
echo " -c CODEC Encoder codec (h264_nvenc, hevc_nvenc, av1_nvenc) (default: h264_nvenc)"
echo " -h Display this help message"
}
# Parse command line arguments
while getopts "n:d:r:f:b:p:c:h" opt; do
case $opt in
n) NUM_SESSIONS="$OPTARG" ;;
d) DURATION="$OPTARG" ;;
r) RESOLUTION="$OPTARG" ;;
f) FRAMERATE="$OPTARG" ;;
b) BITRATE="$OPTARG" ;;
p) PRESET="$OPTARG" ;;
c) CODEC="$OPTARG" ;;
h) usage; exit 0 ;;
?) usage; exit 1 ;;
esac
done
# Function to start an encoding session
encode_session() {
local session_num=$1
local output_file="output_${session_num}.mp4"
local log_file="session_${session_num}.log"
# Add session info to the test pattern
local text="Session ${session_num} - ${CODEC} - ${PRESET}"
ffmpeg -f lavfi -i "testsrc=duration=${DURATION}:size=${RESOLUTION}:rate=${FRAMERATE}" \
-c:v "${CODEC}" \
-preset "${PRESET}" \
-b:v "${BITRATE}" \
-y "${output_file}" > "${log_file}" 2>&1 &
echo "Started session $session_num (PID: $!)"
}
echo "Starting multiple NVENC encoding sessions..."
echo "Configuration:"
echo "- Number of sessions: ${NUM_SESSIONS}"
echo "- Resolution: ${RESOLUTION}"
echo "- Framerate: ${FRAMERATE}"
echo "- Duration: ${DURATION}s"
echo "- Bitrate: ${BITRATE}"
echo "- Preset: ${PRESET}"
echo "- Codec: ${CODEC}"
echo
# Start encoding sessions
for i in $(seq 1 ${NUM_SESSIONS}); do
encode_session $i
sleep 1 # Brief pause between session starts
done
# Wait for all sessions to complete
wait
echo -e "\nAll encoding sessions completed\n"
# Print session statistics
echo "Encoding Statistics:"
for i in $(seq 1 ${NUM_SESSIONS}); do
output_file="output_${i}.mp4"
log_file="session_${i}.log"
if [ -f "${output_file}" ]; then
size=$(du -h "${output_file}" | cut -f1)
# Extract encoding speed from log file
speed=$(grep "speed=" "${log_file}" | tail -n1 | sed 's/.*speed=\s*\([0-9.]*\)x/\1/')
echo "Session $i: Size=${size}, Speed=${speed}x"
else
echo "Session $i: Failed to create output file"
fi
done