-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_gst_rtsp_subtitles_client.py
executable file
·65 lines (54 loc) · 1.68 KB
/
test_gst_rtsp_subtitles_client.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
#!/usr/bin/env python
# -*- coding: utf-8
# Record from an RTSP stream containing subtitles, save in an mp4 file
"""
TODO:
- investigate why subtitles are not synchronized
- understand why we need to re-encode the h264
"""
import sys, os, time, re, time
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
if __name__ == '__main__':
GObject.threads_init()
Gst.init(None)
pipeline = Gst.parse_launch("""
mp4mux name=mux ! filesink location=capture.mp4
rtspsrc location=rtsp://localhost:3002/test latency=0 name=d
d. ! capsfilter caps="application/x-rtp,media=video" ! queue ! rtph264depay ! avdec_h264 ! x264enc bitrate=2100 threads=4 ! mux.video_0
d. ! capsfilter caps="application/x-rtp,media=audio" ! queue ! rtpmp4adepay ! mux.audio_0
d. ! capsfilter caps="application/x-rtp,media=application" ! queue ! rtpgstdepay ! mux.subtitle_0
""")
pipeline.set_state(Gst.State.PLAYING)
t0 = time.time()
bus = pipeline.get_bus()
while True:
msg = bus.poll(Gst.MessageType.ANY, int(1e6))
if msg is None:
if time.time() - t0 > 10:
print("break")
pipeline.send_event(Gst.Event.new_eos())
pipeline.set_state(Gst.State.NULL)
break
continue
t = msg.type
if t == Gst.MessageType.EOS:
print("EOS")
break
pipeline.set_state(Gst.State.NULL)
elif t == Gst.MessageType.ERROR:
err, debug = msg.parse_error()
print("Error: %s" % err, debug)
break
elif t == Gst.MessageType.WARNING:
err, debug = msg.parse_warning()
print("Warning: %s" % err, debug)
elif t == Gst.MessageType.STATE_CHANGED:
pass
elif t == Gst.MessageType.STREAM_STATUS:
pass
else:
print(t)
print("Unknown message: %s" % msg)
print("Bye bye ;)")