I have written a code where I assign a video file to the cv2 module in python script. I am running this python script with PHP. when I run the PHP in the terminal then cv2 can access the video, but when I run the PHP on the webpage then cv2 cannot access the video.
python filename - video2frames.py
PHP filename - script.php
bootscript.php -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>script</title>
</head>
<body>
<?
$out = shell_exec("python3 video2frames.py");
echo "$out";
?>
video2frames.py -
# Importing all necessary libraries
import sys
import os
import cv2
value = 'cv2' in sys.modules
print('Check if true cv2 is imported',value)
# Read the video from specified path
cam = cv2.VideoCapture('video.mp4')
print('cam value : ',cam)
output in terminal -
[customro@heimdall www]$ php bootscript.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>script</title>
</head>
<body>
Check if true cv2 is imported True
cam value : <VideoCapture 0x7f2731224fd0>
</body>
</html>
output in webpage -
Check if true cv2 is imported True cam value :
I Have tried -
- changing permissions of all the files associated with this program to 777
- I have tried exec, system, shell_exec commands to call python file in PHP