I am using python 3.5 on Windows 10
I use a simple script to capture from the WebCam
It produces an avi file called output.avi
This works well
However
Using pyinstaller the exe works but the resulting avi is a blank file ie zero bytes
Can anyone help me
import numpy as np
import cv2
import time
cap = cv2.VideoCapture(1)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
#give camera time to awaken and focus
time.sleep(3)
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
#frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
#QUIT by hitting Q
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
error messages or log content please
No error messages. It writes the output avi but when I go to playback, the avi fails as it is zero bytes
Where do I look for the log.
I am entering pyinstaller --onefile myscript.pyw to make the exe
I should have pointed out that I new to Python
Quote:Where do I look for the log.
Not sure there is one, I just added that in case you knew of one.
(Mar-27-2018, 11:48 AM)TamP Wrote: [ -> ]It writes the output avi but when I go to playback, the avi fails as it is zero bytes
This is because your script runs OK at least up to line #10 where a new empty file is created.
Is there any chance that
while(cap.isOpened())
is never True? How many cameras do you have attached?
cap = cv2.VideoCapture(1)
suggest at least two and you are using the second one (because if device index used is 1)
https://docs.opencv.org/3.1.0/dd/d43/tut...splay.html
There are two cameras but I only use camera(1)
Can I point out that the script works perfectly and the output is fine. It is only when I make an exe with Pyinstaller that the output is Zero bytes
Hi I also have the same problem. I thought that pyinstaller was the problem so I used cx_freeze but the same problem occurs. Pls help us :(
I dont know why, but this script works for me using pyinstaller
The resulting avi plays back
import cv2
import numpy as np
import time
# Create a VideoCapture object
cap = cv2.VideoCapture(1) #camera 1 is the camera I want to record
# Check if camera opened successfully
if (cap.isOpened() == False):
print("Unable to read camera feed")
#Let camera warm up 3 secs
time.sleep(3)
# Default resolutions of the frame are obtained.The default resolutions are system dependent.
# We convert the resolutions from float to integer.
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
# Define the codec and create VideoWriter object.The output is stored in 'AlbaPy.avi' file.
out = cv2.VideoWriter('AlbaPy.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height))
while(True):
ret, frame = cap.read()
if ret == True:
# Write the frame into the file 'output.avi'
out.write(frame)
# Display the resulting frame
cv2.imshow('frame',frame)
# Press Q on keyboard to stop recording
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Break the loop
else:
break
# When everything done, release the video capture and video write objects
cap.release()
out.release()
# Closes all the frames
cv2.destroyAllWindows()
Hi, The problem can be resolved by providing the OPENCV VIDEOIO FFMPEG File. Install opencv-contrib-python of appropriate version. Then execute the following statement.
" pyinstaller -F prog.py --hidden-import pkg_resources.py2_warn --add-binary C:\Users\XXX\Anaconda3\envs\py20\Lib\site-packages\cv2\opencv_ffmpeg341_64.dll;. " [Do not remove the ;.]
Refer the following link for details:
https://stackoverflow.com/questions/4441...ot-opening
2 Answers
Active
Oldest
Votes
3
I just had this same problem and this worked for me:
Use the --add-binary option like BHawk pointed out to copy the dll from the site-packages folder to your dist folder when building the exe.
example:
pyinstaller program.spec --add-binary <PATH_TO_PYTHON>\Lib\site-packages\cv2\opencv_ffmpeg320_64.dll;.
shareimprove this answerfollow
answered Sep 24 '17 at 5:05
Garth5689