CodeFormer icon indicating copy to clipboard operation
CodeFormer copied to clipboard

IndexError when dealing with videos

Open XobilePidor opened this issue 2 years ago • 1 comments
trafficstars

Hi,

Thank you for developing this program.

I ran into troubles when dealing with videos. After a long run of program, it seems that all the pictures are patched, but when saving video, it says:


Video Saving... Traceback (most recent call last): File "C:\Users\xxx\CodeFormer\inference_codeformer.py", line 264, in height, width = video_frames[0].shape[:2] IndexError: list index out of range

After that, output folder is empty (empty folders with no files).

Please help, thank you.

XobilePidor avatar Jan 28 '23 06:01 XobilePidor

Hi~ Did you fixed that? I had the same problem on Windows 10. It seems because your path too long. You can change the folder or try to modify inference_codeformer.py like this

img_list = sorted(glob.glob(os.path.join(result_root, 'final_results', '*.[jp][pn]g')))  
for img_path in img_list:  
            img = cv2.imread(img_path)  
            video_frames.append(img)

to

img_list = sorted(os.listdir(os.path.join(result_root, 'final_results')))  
for img_path in img_list:  
            img = cv2.imread(os.path.join(result_root, 'final_results', img_path))  
            video_frames.append(img)

And if output folder is empty it may because you path with Chinese or others. Then you can try modify img_util.py function imwrite line 151

return cv2.imwrite(file_path, img, params)

to

return cv2.imencode('.png', img)[1].tofile(r'{}'.format(file_path))

but if you do so the variable "params" won't be used.

Hope this helps you.

WhiteEyeYan avatar Mar 03 '23 16:03 WhiteEyeYan