My code is meant to loop through an existing video on file frame by frame and add some text to each frame before writing each image frame to a new file, that should be a video. Additionally, I am adding these images within the loop(one image written to file per iteration of while loop) VS writing all the images at one time at the end of the code.
The final video will be the same as the input video but with some text on them. The code as is does not crash but the output mp4 file says QuickTime cannot open it when I try on my mac and it does not appear to be writing correctly. Here is my code:
cap = cv2.VideoCapture('me_ballin.mov')
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Be sure to use lower case
out = cv2.VideoWriter('OUTPUT_PLEASE.mp4', fourcc, 20.0, (640, 640))
while cap.isOpened():
ret, img = cap.read()
font = cv2.FONT_HERSHEY_SIMPLEX
bottomLeftCornerOfText = (100,250)
fontScale = 2
fontColor = (255,255,255)
lineType = 2
photo_text = "BALLINNNN"
cv2.putText(img, photo_text,
bottomLeftCornerOfText,
font,
fontScale,
fontColor,
lineType)
out.write(img)
As I said, when I run the code it does not crash but the output file OUTPUT_PLEASE.mp4 cannot be opened. Thoughts?