1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| import os from PIL import Image
just_video = True
input_folder = "E:\\BaiduSyncdisk\\NeRF_Proj\\NeRO\\data\\relight\\bear-neon\\" image_file_suffix = None
if not just_video: image_files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.jpg', '.jpeg', '.png', '.gif'))] image_files.sort(key=lambda x:int(x.split('.')[0])) image_num = len(image_files) print('==>图片数量: ' + str(image_num))
out_image_th = 0 image_file_suffix = image_files[0].split('.')[-1] for image_file in image_files: out_image_name = image_num * 2 - 1 - out_image_th out_image_name = str(out_image_name) + '.' + image_file_suffix print("==>正在处理图片:", image_file , '-->' , out_image_name) out_image_th += 1 input_path = os.path.join(input_folder, image_file) output_path = os.path.join(input_folder, out_image_name)
image = Image.open(input_path) image.save(output_path)
print("==>处理完成")
import subprocess
frame = 120 video_name = 'nero_relight.mp4' if image_file_suffix is None: image_file_suffix = 'png' cmds=[ 'ffmpeg', '-r' , str(frame) , '-i' , input_folder + '%d.'+image_file_suffix , '-vf' , "scale=ih*16/9:ih:force_original_aspect_ratio=decrease,pad=ih*16/9:ih:(ow-iw)/2:(oh-ih)/2" , video_name ] subprocess.run(cmds)
|