0

I'm creating a video sample by combining cropped-faced images using Deepface python library.

I saved the cropped faces in a list called cropped_faces. And it has saved all the frames successfully.

The list content of cropped_faces[]:

enter image description here

Finally, I am using cv2.write() method in a for loop to write the frames to the video. The code is as follows:

height,width,layers = cropped_faces[0].shape
print(height,width,layers)

fourcc = cv2.VideoWriter_fourcc(*'H264')
video = cv2.VideoWriter('/content/gdrive/MyDrive/Kaggle/Data/output.mp4', fourcc,1,(width,height))

for j in range(0,5):
  video.write(cropped_faces[j])

video.release()
cv2.destroyAllWindows()

print("The video was successfully saved")

The output:

enter image description here

Although there are no errors in the code, the video saved in the location '/content/gdrive/MyDrive/Kaggle/Data/' is not playable. Only a size 258bytes video is created.

Can somebody please help me to find the reason and solve this issue, please?

enter image description here

Pawara Siriwardhane
  • 1,873
  • 10
  • 26
  • 38
  • make sure to resize all the cropped faces to your video resolutio (width,height) if they are not yet in the right size. Make also sure that the codec is available (you might want to try MJPG for reference) and that your application has access to the ffmpeg shared library. – Micka Nov 09 '22 at 15:21
  • some codecs also have some requirements to the usable resolutions, like being a multiple of 16 or 32 in each dimension. Please try, if necessary. – Micka Nov 09 '22 at 15:23
  • ... and requirements to containers. maybe try mkv. – kallaballa Nov 09 '22 at 19:22
  • Take a look at the [following post](https://stackoverflow.com/questions/28163201/writing-a-video-file-using-h-264-compression-in-opencv). You may try `'avc1'` FOURCC. There may also be a license issue with H264 video codec. I don't know about Google Colab, but in Windows, we have to download an additional DLL for using H.264 codec with OpenCV. `'mp4v'` FOURCC should work, but with poor quality. – Rotem Nov 10 '22 at 22:03

0 Answers0