视频拼接性能汇总
|----|------------|-------|-------|----|------|------------------------|-----------------|---------|-----|-----|-------|----------|----------|------|---|
| 编号 | 方案 | 并行任务数 | 视频分辨率 | 帧率 | 编码格式 | cpu | gpu | cpu使用率% | 线程数 | fps | 耗时秒 | 视频合并后fps | 视频合并总时长秒 | 备注 | |
| 1 | 纯cpu | 1 | 1080P | 25 | H264 | 4核 i5-7500 | | 100 | 1 | 36 | 51 | 1836 | 73 | | |
| 2 | 纯cpu | 1 | 1080P | 25 | H264 | 4核 i5-7500 | | 100 | 4 | 34 | 53 | 1836 | 73 | | |
| 3 | 纯cpu | 1 | 1080P | 25 | H264 | 4核 i5-7500 | | 100 | 8 | 34 | 50 | 1836 | 73 | | |
| 4 | 纯cpu | 1 | 1080P | 25 | H264 | 4核 i5-7500 | | 100 | 16 | 34 | 53 | 1836 | 73 | | |
| 5 | 核显编解 | 1 | 1080P | 25 | H264 | 4核 i5-7500 | HD Graphics 630 | 40 | 默认 | 82 | 22.4 | 1836 | 73 | | |
| 6 | cpu解 + 独显编 | 1 | 1080P | 25 | H264 | 4核 i5-7500 | nvidia 1050ti | 100 | 默认 | 192 | 9 | 1836 | 73 | | |
| 7 | 独显解+独显编 | 1 | 1080P | 25 | H264 | 4核 i5-7500 | nvidia 1050ti | 25 | 默认 | 185 | 10 | 1836 | 73 | | |
| 8 | cpu解 + 独显编 | 1 | 1080P | 25 | H264 | 24核 i7-13700K 3.40 GHz | nvidia 3090ti | 20 | 默认 | 447 | 4 | 1836 | 73 | | |
| 9 | 独显解+独显编 | 1 | 1080P | 25 | H264 | 24核 i7-13700K 3.40 GHz | nvidia 3090ti | 0 | 默认 | 424 | 4 | 1836 | 73 | | |
| 10 | cpu解 + 独显编 | 1 | 1080P | 25 | H264 | 4核 i5-7500 | nvidia 1050ti | 100 | 默认 | 407 | 11.22 | | 180 | | |
| 11 | cpu解 + 独显编 | 3 | 1080P | 25 | H264 | 4核 i5-7500 | nvidia 1050ti | 100 | 默认 | 416 | 32.96 | | 180 | | |
| 12 | cpu解 + 独显编 | 5 | 1080P | 25 | H264 | 4核 i5-7500 | nvidia 1050ti | 100 | 默认 | 424 | 53.75 | | 180 | | |
| 13 | cpu解 + 独显编 | 10 | 1080P | 25 | H264 | 4核 i5-7500 | nvidia 1050ti | 100 | 默认 | 416 | 87.6 | | 180 | 2路异常 | |
| | | | | | | | | | | | | | | | |
1.测试环境:
设备名称 DESKTOP-5REGCE3
处理器 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz 3.41 GHz 4核
机带 RAM 16.0 GB
设备 ID 4C08B4E2-53DE-42EC-A586-94C740F16A36
产品 ID 00331-10000-00001-AA715
系统类型 64 位操作系统, 基于 x64 的处理器
笔和触控 没有可用于此显示器的笔或触控输入
gpu卡:nvidia 1050ti
核数:4
视频文件:
src_1.mp4 1080P@25fps 30秒
src_2.mp4 1080P@25fps 44秒
拼接后视频总时长:74秒 总帧数(1836)
测试工具:
D:\test> ffmpeg -version
ffmpeg version 6.0-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
2.使用cpu拼接:
1)默认线程数cpu (线程数设置并无效果)
执行命令:
Measure-Command {ffmpeg -threads 1 -i src_1.mp4 -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 -c copy copy_7.mp4}
cpu:100%
执行结果:frame= 1836 fps= 36 q=-1.0 Lsize= 17465kB time=00:01:13.32 bitrate=1951.4kbits/s speed=1.42x
执行时间:51秒
2)线程数cpu:4
执行命令:
Measure-Command {ffmpeg -threads 4 -i src_1.mp4 -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 outputVideo_8.mp4}
cpu:100%
执行结果:frame= 1836 fps= 34 q=-1.0 Lsize= 17465kB time=00:01:13.32 bitrate=1951.4kbits/s speed=1.37x
执行时间:53秒
3)线程数cpu:8
执行命令:
Measure-Command {ffmpeg -threads 8 -i src_1.mp4 -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 outputVideo_9.mp4}
cpu:100%
执行结果:frame= 1836 fps= 37 q=-1.0 Lsize= 17465kB time=00:01:13.32 bitrate=1951.4kbits/s speed=1.46x
执行时间:50秒
4)线程数cpu:16
执行命令:
Measure-Command {ffmpeg -threads 16 -i src_1.mp4 -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 outputVideo_9.mp4}
cpu:100%
执行结果:frame= 1836 fps= 34 q=-1.0 Lsize= 17465kB time=00:01:13.32 bitrate=1951.4kbits/s speed=1.37x
执行时间:53秒
5)cpu核显:核显(忠后工作机 i5-7500@3.4GHZ Intel(R) HD Graphics 630)
执行命令:
Measure-Command {ffmpeg -hwaccel qsv -i src_1.mp4 -hwaccel qsv -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 -c:v h264_qsv -preset fast qsv_01.mp4}
cpu:40%
执行结果:frame= 1836 fps= 82 q=26.0 Lsize= 11301kB time=00:01:13.32 bitrate=1262.7kbits/s speed=3.28x
video:11277kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.215376%
执行时间:22.4秒
6)默认命令(cpu解码 gpu编码 1050ti)
执行命令:
Measure-Command {ffmpeg -i src_1.mp4 -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 -c:v h264_nvenc -preset fast -profile:v high cuda_2.mp4}
cpu:100%
gpu encoder:50%
执行结果:frame= 1836 fps=192 q=22.0 Lsize= 16955kB time=00:01:13.40 bitrate=1892.3kbits/s speed=7.67x
执行时间:9秒
7)默认命令(gpu解码 gpu编码 1050ti)
执行命令:
Measure-Command {ffmpeg -hwaccel nvdec -i src_1.mp4 -hwaccel nvdec -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 -c:v h264_nvenc -preset fast -profile:v high cuda_2.mp4}
cpu:25%
gpu encoder:42%
gpu decoder:26%
执行结果:frame= 1836 fps=185 q=22.0 Lsize= 16955kB time=00:01:13.40 bitrate=1892.3kbits/s speed= 7.4x
执行时间:10秒
8)(cpu解码 gpu编码3090ti) 3090ti
账户:A 密码:125521 windows11:192.168.42.105
D:\test>nvidia-smi
Fri Apr 26 14:32:17 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 546.33 Driver Version: 546.33 CUDA Version: 12.3 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3090 WDDM | 00000000:01:00.0 On | N/A |
| 47% 53C P0 114W / 350W | 778MiB / 24576MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
执行命令:
Measure-Command {ffmpeg -i src_1.mp4 -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 -c:v h264_nvenc -preset fast -profile:v high cuda_2.mp4}
cpu:20%
gpu encoder:100%
gpu decoder:0%
执行结果:frame= 1836 fps=447 q=22.0 Lsize= 16950kB time=00:01:13.40 bitrate=1891.7kbits/s speed=17.9x
执行时间:4秒
9)(gpu解码 gpu编码3090ti) 3090ti
账户:A 密码:125521 windows11:192.168.42.105
D:\test>nvidia-smi
Fri Apr 26 14:32:17 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 546.33 Driver Version: 546.33 CUDA Version: 12.3 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3090 WDDM | 00000000:01:00.0 On | N/A |
| 47% 53C P0 114W / 350W | 778MiB / 24576MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
执行命令:
Measure-Command {ffmpeg -hwaccel nvdec -i src_1.mp4 -hwaccel nvdec -i src_2.mp4 -filter_complex xfade=transition=fade:duration=1:offset=29 -c:v h264_nvenc -preset fast -profile:v high cuda_2.mp4}
gpu encoder:100%
gpu decoder:100%
执行结果:frame= 1836 fps=424 q=22.0 Lsize= 16950kB time=00:01:13.40 bitrate=1891.7kbits/s speed=16.9x
执行时间:4秒
并行运行测试代码:
python
import subprocess
import time
# 定义要执行的命令列表
commands = [
['ffmpeg', '-hwaccel', 'nvdec', '-i', 'src_90_3.mp4', '-hwaccel', 'nvdec', '-i', 'src_90_4.mp4', '-filter_complex', 'xfade=transition=fade:duration=1:offset=89', '-c:v', 'h264_nvenc', '-preset', 'fast', '-profile:v', 'high', '3_1.mp4'],
['ffmpeg', '-hwaccel', 'nvdec', '-i', 'src_90_5.mp4', '-hwaccel', 'nvdec', '-i', 'src_90_6.mp4', '-filter_complex', 'xfade=transition=fade:duration=1:offset=89', '-c:v', 'h264_nvenc', '-preset', 'fast', '-profile:v', 'high', '3_2.mp4'],
['ffmpeg', '-hwaccel', 'nvdec', '-i', 'src_90_7.mp4', '-hwaccel', 'nvdec', '-i', 'src_90_8.mp4', '-filter_complex', 'xfade=transition=fade:duration=1:offset=89', '-c:v', 'h264_nvenc', '-preset', 'fast', '-profile:v', 'high', '3_3.mp4']
]
# 启动并行进程
processes = []
start_times = []
for i, command in enumerate(commands):
start_time = time.time() # 记录开始时间
stdout_file = f"process_{i+1}_stdout.log"
stderr_file = f"process_{i+1}_stderr.log"
print(" ".join(command))
with open(stdout_file, 'w') as stdout, open(stderr_file, 'w') as stderr:
process = subprocess.Popen(command, stdout=stdout, stderr=stderr)
processes.append(process)
start_times.append(start_time)
# 等待所有进程完成并打印执行时间
for i, process in enumerate(processes):
process.wait()
end_time = time.time() # 记录结束时间
execution_time = end_time - start_times[i] # 计算执行时间
print(f"进程 {i+1} 执行时间: {execution_time:.2f} 秒")
print("所有进程已完成.")