0

I am trying to write a video with cv2 in Python3 and I get the following message:

"Could not find encoder for codec id 27: Encoder not found".

Here's my code:

video_writer = cv2.VideoWriter()
video_writer.open(filename, cv2.VideoWriter_fourcc(*"avc1"), fps, (width, height), True)
for frame in frames:
   video_writer.write(image_size_correction(frame, width, height))
video_writer.release()
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Blackgold97
  • 11
  • 1
  • 2

2 Answers2

1

Turns out open cv install via pip does not have access to the avc1 codec because of licensing issues. If you instead make it from source it fixes the issue.

Blackgold97
  • 11
  • 1
  • 2
1

If you are using conda, the following worked for me on Ubuntu 20.04:

  1. Uninstall OpenCV through pip (pip uninstall opencv-python opencv-contrib-python)
  2. Install OpenCV using conda (conda install -c conda-forge opencv)

Now, I can run cv2.VideoWriter('out.mp4', cv2.VideoWriter_fourcc(*'avc1'), FPS, (WIDTH, HEIGHT)) without any issues!

Raj K
  • 329
  • 1
  • 7