I am facing a problem with the python script when called by PHP.
The python script is working great when I run it from the terminal.
but when I call the python script from PHP it runs half, when statements of the cv2 module come the code does not work
I have imported cv2 module
the python script is
video2frames.py
# Importing all necessary libraries
import cv2
import os
# Read the video from specified path
cam = cv2.VideoCapture("input/video.mp4")
try:
# creating a folder named data
if not os.path.exists('input/frames'):
os.makedirs('input/frames')
# if not created then raise error
except OSError:
print ('Error: Creating directory of frames')
# frame
currentframe = 0
print('till before while loop worked')
a = 1
while(a<250):
# reading from frame
print('worked inside while loop')
ret,frame = cam.read()
if ret:
# if video is still left continue creating images
print('worked inside if condition')
name = './input/frames/frame' + str(currentframe) + '.png'
print ('Creating...' + name)
# writing the extracted images
cv2.imwrite(name, frame)
# increasing counter so that it will
# show how many frames are created
currentframe += 1
print('worked inside if')
else:
print('worked inside else');break
# Release all space and windows once done
cam.release()
cv2.destroyAllWindows()
the PHP code I used to call the python script is
shell_exec('python3 video2frames.py');