|
|
@ -737,31 +737,47 @@ Videos can be published with `VideoWriter`: |
|
|
|
```python |
|
|
|
```python |
|
|
|
import cv2 |
|
|
|
import cv2 |
|
|
|
import numpy as np |
|
|
|
import numpy as np |
|
|
|
from time import sleep |
|
|
|
from time import sleep, time |
|
|
|
|
|
|
|
|
|
|
|
fps = 20 |
|
|
|
fps = 15 |
|
|
|
width = 800 |
|
|
|
width = 800 |
|
|
|
height = 600 |
|
|
|
height = 600 |
|
|
|
|
|
|
|
colors = [ |
|
|
|
|
|
|
|
(0, 0, 255), |
|
|
|
|
|
|
|
(255, 0, 0), |
|
|
|
|
|
|
|
(0, 255, 0), |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
out = cv2.VideoWriter('appsrc ! videoconvert' + \ |
|
|
|
out = cv2.VideoWriter('appsrc ! videoconvert' + \ |
|
|
|
' ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=40' + \ |
|
|
|
' ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=' + str(fps * 2) + \ |
|
|
|
|
|
|
|
' ! video/x-h264,profile=baseline' + \ |
|
|
|
' ! rtspclientsink location=rtsp://localhost:8554/mystream', |
|
|
|
' ! rtspclientsink location=rtsp://localhost:8554/mystream', |
|
|
|
cv2.CAP_GSTREAMER, 0, fps, (width, height), True) |
|
|
|
cv2.CAP_GSTREAMER, 0, fps, (width, height), True) |
|
|
|
if not out.isOpened(): |
|
|
|
if not out.isOpened(): |
|
|
|
raise Exception("can't open video writer") |
|
|
|
raise Exception("can't open video writer") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
curcolor = 0 |
|
|
|
|
|
|
|
start = time() |
|
|
|
|
|
|
|
|
|
|
|
while True: |
|
|
|
while True: |
|
|
|
frame = np.zeros((height, width, 3), np.uint8) |
|
|
|
frame = np.zeros((height, width, 3), np.uint8) |
|
|
|
|
|
|
|
|
|
|
|
# create a red rectangle |
|
|
|
# create a rectangle |
|
|
|
|
|
|
|
color = colors[curcolor] |
|
|
|
|
|
|
|
curcolor += 1 |
|
|
|
|
|
|
|
curcolor %= len(colors) |
|
|
|
for y in range(0, int(frame.shape[0] / 2)): |
|
|
|
for y in range(0, int(frame.shape[0] / 2)): |
|
|
|
for x in range(0, int(frame.shape[1] / 2)): |
|
|
|
for x in range(0, int(frame.shape[1] / 2)): |
|
|
|
frame[y][x] = (0, 0, 255) |
|
|
|
frame[y][x] = color |
|
|
|
|
|
|
|
|
|
|
|
out.write(frame) |
|
|
|
out.write(frame) |
|
|
|
print("frame written to the server") |
|
|
|
print("frame written to the server") |
|
|
|
|
|
|
|
|
|
|
|
sleep(1 / fps) |
|
|
|
now = time() |
|
|
|
|
|
|
|
diff = (1 / fps) - now - start |
|
|
|
|
|
|
|
if diff > 0: |
|
|
|
|
|
|
|
sleep(diff) |
|
|
|
|
|
|
|
start = now |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### From a UDP stream |
|
|
|
### From a UDP stream |
|
|
@ -770,7 +786,7 @@ The server supports ingesting UDP/MPEG-TS packets (i.e. MPEG-TS packets sent wit |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|
gst-launch-1.0 -v mpegtsmux name=mux alignment=1 ! udpsink host=238.0.0.1 port=1234 \ |
|
|
|
gst-launch-1.0 -v mpegtsmux name=mux alignment=1 ! udpsink host=238.0.0.1 port=1234 \ |
|
|
|
videotestsrc ! video/x-raw,width=1280,height=720 ! x264enc speed-preset=ultrafast bitrate=6000 key-int-max=40 ! mux. \ |
|
|
|
videotestsrc ! video/x-raw,width=1280,height=720 ! x264enc speed-preset=ultrafast bitrate=3000 key-int-max=60 ! video/x-h264,profile=high ! mux. \ |
|
|
|
audiotestsrc ! audioconvert ! avenc_aac ! mux. |
|
|
|
audiotestsrc ! audioconvert ! avenc_aac ! mux. |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|