autodl做了镜像:高清RealBasicVSR
首先在剪映将视频剪好导出,最多是720像素的,不然后面超分的时候会爆显存。剪映视频也最好是双数帧数结尾的,不然超分的时候单数图片会报错->RuntimeError: non-empty 3D or 4D input tensor expected but got ndim: 4
首先使用脚本把视频分割成图片
import cv2
import os
video_directory = r'D:\hc\dongtaibizhi\test'
video_files = [f for f in os.listdir(video_directory) if f.endswith('.mp4')]
for video_file in video_files:
video_path = os.path.join(video_directory, video_file)
output_folder = os.path.join(video_directory, os.path.splitext(video_file)[0])
os.makedirs(output_folder, exist_ok=True)
cap = cv2.VideoCapture(video_path)
original_fps = int(cap.get(cv2.CAP_PROP_FPS))
frames_per_second = 30
frame_skip = max(1, original_fps // frames_per_second)
frame_count = 0
while True:
ret, frame = cap.read()
if not ret:
break
if frame_count % frame_skip == 0:
image_filename = os.path.join(output_folder, f'frame_{frame_count:04d}.jpg')
cv2.imwrite(image_filename, frame)
frame_count += 1
cap.release()
print(f'已成功保存 {video_file} 的图片到 {output_folder}')
比如说现在图片集都放在ss3720这个文件夹里,那么运行命令进行图片高清化
python inference_realbasicvsr.py configs/realbasicvsr_x4.py checkpoints/RealBasicVSR_x4.pth data/ss3720 results/ss3720 --max_seq_len=2
超分后使用~/RealBasicVSR-master/results,下的脚本进行图片合成视频(要改脚本里的文件路径)
python image2video.py
参考网址:https://blog.csdn.net/zhiweihongyan1/article/details/124645615