1

There are a number of related questions, however none of the solutions appear to work. The primary solution I can find on SO is related to input size, which I believe I have corrected for. Nevertheless, I have the following issue:

I have a number of images that I want to use as frames:

frame_0001.png
frame_0002.png
frame_.....etc

I load them all in:

frames_location = glob.glob(r'stimuli\ambush_1\frame_*.png')
frames = []
for frame in frames_location:
    frames.append(cv2.imread(frame))

Next, I use the following function to convert this list of frames into a video:

def frames_to_video(frames, name='test.mp4'):
    
    w,h,_ = frames[0].shape # extract size information

    fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') 
    writer = cv2.VideoWriter(name, fourcc, 20,  (w,h) )

    for frame in frames:
        writer.write(frame)
    writer.release()

video = frames_to_video(frames)

Running this code creates a test.mp4 video as expect, which is 1kb large. The images I load in are each around 300kb so that's already a first signal something is wrong. Trying to play the video returns a 0xc10100be error.

Where I am I going wrong? What's wrong with my code?

I'm running Python 3.9.6 with a OpenCv 4.5.3 install.

4
  • 1
    Make sure the environment has access to the opencv_ffmpeg dll and that h264 encoder is available. Try whether images are loaded correctly (e.g. imshow in the loop) and try with different codecs like mjpg (.avi) as well.
    – Micka
    Commented Jul 17, 2021 at 9:55
  • 1
    And in doubt use a resize of the images to force the right resolution for all of them.
    – Micka
    Commented Jul 17, 2021 at 9:56
  • @Micka I now resize each one, and I check if it can open the first image. Both appears to work. I am not sure if it has the dll and encoder, so I will check this now Commented Jul 17, 2021 at 10:19
  • 1
    @Micka Turned out I did not have the dll. Commented Jul 17, 2021 at 10:39

1 Answer 1

3

Turned out I was missing a dll file.

More specifically, I had installed opencv using pip. However, I had not chosen the contrib version.

As such, to fix it was simple

py -m pip uninstall opencv-python
py -m pip install opencv-contrib-python
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.