forked from ASURT-ROV-18/RPI_18
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoStream.py
52 lines (45 loc) · 2.17 KB
/
VideoStream.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
import threading
import time
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
class VideoStream():
def __init__(self, pipeline):
Gst.init(None)
self._pipeline = Gst.parse_launch(pipeline)
# "v4l2src device=/dev/video0 ! image/jpeg, width=1280, height=720, framerate=60/1 ! rtpjpegpay ! udpsink host=" + self._ip + " port=" + self._port + "sync=false")
self._thread = None
def start(self):
ret = self._pipeline.set_state(Gst.State.PLAYING)
if ret == Gst.StateChangeReturn.FAILURE:
raise Exception("Error starting the pipeline")
# self._running = True
# if (self._thread is None) or (not self._thread.isAlive()):
# self._thread = threading.Thread(target=self._run, args=())
# self._thread.start()
# def _run(self):
# bus = self._pipeline.get_bus()
#
# while True:
# if not self._running:
# break
# message = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE,
# Gst.MessageType.STATE_CHANGED | Gst.MessageType.ERROR | Gst.MessageType.EOS)
# if message.type == Gst.MessageType.ERROR:
# err, debug = message.parse_error()
# # print("Debugging information: %s" % debug, file=sys.stderr)
# raise Exception("Error received from element %s: %s" % (message.src.get_name(), err), file=sys.stderr)
# elif message.type == Gst.MessageType.EOS:
# #print("End-Of-Stream reached.")
# break
# elif message.type == Gst.MessageType.STATE_CHANGED:
# if isinstance(message.src, Gst.Pipeline):
# old_state, new_state, pending_state = message.parse_state_changed()
# #print("Pipeline state changed from %s to %s." % (old_state.value_nick, new_state.value_nick))
# else:
# raise Exception("Unexpected message received.")
def pause(self):
self._pipeline.set_state(Gst.State.PAUSED)
def close(self):
self._running = False
self._pipeline.set_state(Gst.State.NULL)