I have a simple Python code that used to work fine, but now it crashes every time with the message “The kernel for withPillow.ipynb appears to have died. It will restart automatically.”
The script is supposed to export frames from a video file, using the Pillow library. It used to work fine a few days ago, but now it only produces a couple of images (instead of several thousands as it worked previously).
Can you help me diagnose the problem? I don’t know where to look for (logs, etc.)
This is the complete code:
from PIL import Image # this is using Pillow (https://pillow.readthedocs.io/en/stable/index.html)
import cv2
# Global variables and options
InputVideoFile = "input.mp4"
OutPutFolder = "img-seq-openCV-PIL-2/"
VideoExtension = '.tiff'
# Open the video file
vidcap = cv2.VideoCapture(InputVideoFile)
# Loop through each frame in the video
success, image = vidcap.read()
count = 0
while success:
# Define the output file name for the current frame
output_filename = OutPutFolder + str(f"frame_{count:04}.tiff")
# Write the current frame to the output file as a TIFF image
img = Image.fromarray(image)
img.save(output_filename, format='TIFF', compression='tiff_deflate', tiffinfo={})
print(f"frame_{count:04}.tiff")
# Read the next frame from the video
success, image = vidcap.read()
count += 1
# Release the video file
vidcap.release()