Click here to Skip to main content
15,666,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I'm trying to convert with ffmpeg-python every frame of a video in a numpy array that could work with opencv

What I have tried:

Here my code:

<pre><pre lang="Python">for i in (frames):
    out, _ = (
        .output('pipe:',vframes=frames, format='rawvideo', pix_fmt='rgb24')

    video = (
        .frombuffer(out, np.uint8)
        .reshape([-1, 1920, 1080, 3])

    print(f'Array from ffmpeg: {video}')

The code works and it creates a numpy array, but it does not work with opencv.
When I pass inside the for loop the array to opencv I get this error
imgS = cv2.resize(video, (0, 0), None, 0.5, 0.5)
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)

error: (-215:Assertion failed) !dsize.empty() in function 'cv::resize'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900