-
Notifications
You must be signed in to change notification settings - Fork 37
/
videocontrolmod.py
executable file
·125 lines (89 loc) · 4.42 KB
/
videocontrolmod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from __future__ import print_function
from subprocess import call , Popen
import sys
import time
import logindbmod
videostreamport="5022" #previous setting 5022
################## ------- VLC section
# In case of use of VLC the code below works
#stream = "sudo -u pi cvlc --no-audio v4l2:///dev/video0 --v4l2-width 1920 --v4l2-height 1440 --v4l2-chroma MJPG --v4l2-hflip 1 --v4l2-vflip 1 --sout '#standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8554/}' -I dummy &"
#def streamedit(dictdata):
# width="1920"
# height="1440"
# fps="10"
# video="video0"
# if "width" in dictdata:
# width=dictdata["width"]
# if "height" in dictdata:
# height=dictdata["height"]
# if "fps" in dictdata:
# fps=dictdata["fps"]
# if "video" in dictdata:
# video=dictdata["video"]
# stream = "sudo -u pi cvlc --no-audio v4l2:///dev/"+video+" --v4l2-fps "+fps+" --v4l2-width "+width+" --v4l2-height "+height+" --v4l2-chroma MJPG --v4l2-hflip 1 --v4l2-vflip 1 --sout '#standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8554/}' -I dummy &"
# return stream
################## ------- END
def streamedit(dictdata):
#./mjpg_streamer -i "./input_uvc.so -d /dev/video1 -r 640x480" -o "./output_http.so -w ./www"
username=logindbmod.getusername()
password=logindbmod.getpassword()
width="1024"
height="768"
fps="15"
video="video0"
if "width" in dictdata:
width=dictdata["width"]
if "height" in dictdata:
height=dictdata["height"]
if "fps" in dictdata:
fps=dictdata["fps"]
if "video" in dictdata:
video=dictdata["video"]
global videostreamport
if (video=="video0")and(int(width)>1024):
print("try using the raspicam")
stream="mjpg_streamer -i '/usr/local/lib/mjpg-streamer/input_raspicam.so -d /dev/"+video+" -x "+width+" -y "+height+" -fps "+fps+"' -o '/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p "+videostreamport+"' &"
#stream="mjpg_streamer -i '/usr/local/lib/mjpg-streamer/input_raspicam.so -d /dev/"+video+" -x "+width+" -y "+height+" -fps "+fps+"' -o '/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p "+videostreamport+" -c "+username+":"+password+"' &"
else:
stream="mjpg_streamer -i '/usr/local/lib/mjpg-streamer/input_uvc.so -d /dev/"+video+" -r "+width+"x"+height+" -f "+fps+"' -o '/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p "+videostreamport+"' &"
#stream="mjpg_streamer -i '/usr/local/lib/mjpg-streamer/input_uvc.so -d /dev/"+video+" -r "+width+"x"+height+" -f "+fps+"' -o '/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p "+videostreamport+" -c "+username+":"+password+"' &"
#mjpg_streamer -i "/usr/local/lib/mjpg-streamer/input_uvc.so -d /dev/video0 -r 1920x1080" -o "/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p 8090"
#stream = "sudo -u pi cvlc --no-audio v4l2:///dev/"+video+" --v4l2-fps "+fps+" --v4l2-width "+width+" --v4l2-height "+height+" --v4l2-chroma MJPG --v4l2-hflip 1 --v4l2-vflip 1 --sout '#standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8554/}' -I dummy &"
return stream
def stream_video(videodev="",resolution={}):
stop_stream()
resollist=resolution.split("x")
dictdata={"width":resollist[0], "height":resollist[1], "fps":resollist[2]}
if videodev:
dictdata["video"]=videodev
stream=streamedit(dictdata)
done=False
try:
print("starting streaming\n%s" % stream)
call ([stream], shell=True)
except:
print("Exception error failed to start VLC streaming ")
return "Exception"
else:
print("Streaming")
done="Streaming"
return done
def stop_stream_VLC():
print("stopping streaming")
#call (["pkill raspivid"], shell=True)
call (["sudo pkill vlc"], shell=True)
def stop_stream(blockingtype="blocking"):
# non blocking subprocess.Popen
# blocking subprocess.call
print("stopping streaming")
#call (["pkill mjpg_streamer"], shell=True)
if blockingtype=="blocking":
call (["sudo pkill mjpg_streamer"], shell=True)
else:
Popen (["sudo pkill mjpg_streamer"], shell=True)
if __name__ == '__main__':
# comment
#a=[]
#print a
#connectedssid()
stream_video()