forked from SelimEmre/webrtc-ant-media
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvideo_processing.py
More file actions
63 lines (45 loc) · 1.65 KB
/
video_processing.py
File metadata and controls
63 lines (45 loc) · 1.65 KB
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
from webrtc import WebRTCAdapter, init_gstreamer
from gi.repository import Gst
import numpy as np
from PIL import Image
appname = "live"
WEBSOCKET_URL = 'wss://test.antmedia.io/' + appname + '/websocket'
def on_decoded_audio_buffer(pad, info, u_data):
gst_buffer = info.get_buffer()
if not gst_buffer:
print("Unable to get GstBuffer ")
return
if not gst_buffer:
print("failed to get buffer")
(result, mapinfo) = gst_buffer.map(Gst.MapFlags.READ)
assert result
return Gst.PadProbeReturn.OK
def on_decoded_video_buffer(pad, info, streamId):
caps = pad.get_current_caps()
if caps:
structure = caps.get_structure(0)
width = structure.get_int("width")[1]
height = structure.get_int("height")[1]
format = structure.get_string("format")
print(width, height, streamId, format)
gst_buffer = info.get_buffer()
if not gst_buffer:
print("Unable to get GstBuffer ")
(result, mapinfo) = gst_buffer.map(Gst.MapFlags.READ)
assert result
numpy_frame = np.ndarray(
shape=(height, width, 3),
dtype=np.uint8,
buffer=mapinfo.data)
img = Image.fromarray(numpy_frame)
img.save(streamId+".jpeg")
img.close()
gst_buffer.unmap(mapinfo)
return Gst.FlowReturn.OK
init_gstreamer()
webrtc_adapter = WebRTCAdapter(WEBSOCKET_URL)
webrtc_adapter.connect() # replace publish call with play to play the stream
# pass none in audio or video callbacks if you are not interested in them
webrtc_adapter.play("test", on_decoded_video_buffer,
on_decoded_audio_buffer)
# set above callback to none if you don't want any of them