Video runs for a few frames then gives error

Related searches

I'm working on raspberry pi3 model b+ I installed opencv 3.4.4 on my raspberry pi , and it installed fine. I'm just running a basic code to see my camera output . (i have plugged in two cameras)

Here is the code .

import cv2
import time

def show_webcam(mirror=False):
    frame_rate = 30
    prev = 0
    cam = cv2.VideoCapture(0)
    cam1 = cv2.VideoCapture(1)
    ff= 0.5

    fxx = ff
    fyy = ff 
    while True:
        ret_val, img =
        img2 =[1]
        time_elapsed = time.time() - prev
       # print('data type of frame', type(img))
        if time_elapsed > 1/frame_rate:
            prev = time.time()
            small_frame = cv2.resize(img, (0, 0), fx=fxx, fy=fyy)
            cv2.resize(img2,(0, 0), fx = fxx, fy = fyy)
        #if mirror: 
        #    img = cv2.flip(img, 1)
            cv2.imshow('my webcam', img)
            cv2.imshow('my 2nd webcam', img2)
        #if cv2.waitKey(1) == 27: 
        #    break  # esc to quit
        if cv2.waitKey(1) == 27:
    print (cam)

def main():

if __name__ == '__main__':

The videos appear for a few frames but after a few seconds i get this error

select timeout
VIDIOC_DQBUF: Resource temporarily unavailable
Traceback (most recent call last):
  File "", line 39, in <module>
  File "", line 36, in main
  File "", line 21, in show_webcam
    small_frame = cv2.resize(img, (0, 0), fx=fxx, fy=fyy)
cv2.error: OpenCV(3.4.4) /home/pi/packaging/opencv-python/opencv/modules/imgproc/src/resize.cpp:3784: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

This same code works fine when i implement it on my laptop. What can i do to correct this error and ensure the video is not interrupted ?

have tried doing cv2.waitKey(30) doesn't work

why you are using a time_elapsed variable while you can just use the waitkey function and pass to it the milli-sec you want to wait, 1000/framePerSecond. and about your error, the frame you try to resize is empty, sometimes that happens. so before you do any image processing try to check if image image not empty then proceed what you want to do.

Why do I get a playback error for a few seconds before video starts , For some reason when I go to watch a video, I get a playback error, then it changes to a different error, then after a few seconds, it then plays. It seems like the errors I'm getting before a video starts are the ads being blocked� If the video error reads, the codec does not support the video, then get the desired codec pack by first uninstalling the older one. You can obtain the codec from a third-party vendor too. However, a video repair software like Stellar Repair for Video can also fix the codec error making your videos playable.

Same code works on laptop but not on pi. This means you have issues to lesser memory and / or cpu on a smaller device.

Try reducing the framerate to adjust how many frames you can work with a smaller device.

20 most common video errors & how to fix them, This article guide you how to fix all 20 problems or errors while playing videos like playback Below are mentioned some of the common video related problems with their Often during video editing of heavy files, the PC crashes or gets too slow. If the video error reads, the codec does not support the video, then get the� 5. Run Windows 10 Troubleshooting to fix video playback. Windows 10 users can also fix corrupt or unplayable videos by running Video Playback Troubleshooting feature. The feature detects and fixes video problems occurring in Windows 10. Steps to running Windows 10 Troubleshooting feature. Type troubleshooting in Search bar. Select Troubleshooting.

You should check if the ret_val of both is true simultaneously before continuing processing. So when a frame is not properly grabbed, it is dropped and the process is retried instead of throwing an error and exiting.

This does not technically resolve the error, but it does solve your problem, provided the resulting framerate is sufficient for your application.

How to Stop HD Video from Freezing while Playing in VLC, The HD video freezes and skips a few frames while the audio plays perfectly. The video This is an error that is not so rare to the users of VLC. Fortunately� Video Driver Issues Video driver or graphics driver is also one of the major causes of stuttering in games. It is always recommended to install the latest video drivers for the latest games. However, sometimes the latest graphics driver can also be the root of the problem, and in such cases, it is better to revert to the older stable drivers.

Display Problems Playing Video Clips in Windows, window, even though the sound plays correctly. Some systems may experience hesitation problems with the video, where it continually starts restarting Windows and then try to play videos. If it still fails, follow these steps to� Most issues related to Error Compiling Movie errors are related to Media Cache and Media Cache Database which holds.CFA and.PEK files generated by Premiere Pro while importing a clip (s) for the first time in the Project bin. This issue might be related to any Audio/Video effects applied to clip (s) in a sequence (s).

How to Fix Frozen Video Files when Playing?, With the help of video repair tool to fix frozen video files when playing. Q: "I have a video in high definition and when I play it, it has an annoying freezing problem. the features offered by Recoverit Video Repair Tool is provided below in order to give you an After that, it will take a few seconds to save the repaired video. It is like the tape runs over it self for just a few frames causing a flicker or line thru a small part of the video. An idea was that maybe tape baking could iron out these small crackles. The picture is normally not 100% damaged it just has a few lines of errors which only last a few frames.

Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.