Upgraded to gstreamer1.0

This commit is contained in:
Sebastian 2016-06-16 19:32:17 +02:00
parent 2d2558b647
commit 5025773aa1
5 changed files with 49 additions and 50 deletions

View File

@ -3,9 +3,9 @@ import os
import threading
from time import sleep
import pygst
pygst.require('0.10')
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
from feed import Feed
@ -29,10 +29,10 @@ class CameraFeed(Feed):
if os.path.exists(self._feed_pipe):
print '[%s] not starting because feed pipe already exists' % self._name
return
print '[%s] is starting' % self._name
self._running = True
self._thread = threading.Thread(target=self._run)
self._thread = threading.Thread(target=self._run)
self._thread.start()
@ -41,17 +41,19 @@ class CameraFeed(Feed):
mixer_format = MIXER_FORMAT % {'width' : MIXER_WIDTH, 'height' : MIXER_HEIGHT, 'framerate' : MIXER_FRAMERATE}
sink = FEED_SINK % {'feed_pipe' : self._feed_pipe, 'shm_size' : SHM_SIZE}
self._pipeline = gst.parse_launch('%s ! %s ! %s ! %s' % (src, SCALE, mixer_format, sink))
print '%s ! %s ! %s ! %s' % (src, SCALE, mixer_format, sink)
self._pipeline.set_state(gst.STATE_PLAYING)
self._pipeline = Gst.parse_launch('%s ! %s ! %s ! %s' % (src, SCALE, mixer_format, sink))
self._pipeline.set_state(Gst.State.PLAYING)
print "[%s] is playing" % self._name
bus = self._pipeline.get_bus()
msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE, gst.MESSAGE_ERROR | gst.MESSAGE_EOS)
msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS)
print "[%s] %s" % (self._name, msg.parse_error()[1])
self._pipeline.set_state(gst.STATE_NULL)
self._pipeline.set_state(Gst.State.NULL)
self._running = False
print "[%s] has stopped" % self._name

View File

@ -1,9 +1,9 @@
#!/bin/env python2
CAMERA_FEEDS = {
'/tmp/feed1' : '192.168.1.100',
'/tmp/feed2' : '192.168.1.101',
'/tmp/feed3' : '192.168.1.102',
'/tmp/feed1' : '192.168.2.20',
# '/tmp/feed2' : '192.168.2.30',
# '/tmp/feed3' : '192.168.2.40',
}
MIXER_PIPE = '/tmp/mixer1'
@ -19,15 +19,13 @@ OUTPUT_PORT = 6666
FEED_SOURCE = 'rtspsrc location=rtsp://%(ip)s ! rtph264depay ! h264parse ! ffdec_h264'
MIXER_FORMAT = 'video/x-raw-rgb, bpp=(int)32, endianness=(int)4321, format=(fourcc)BGRA,'\
+ ' red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216,'\
+ ' width=(int)%(width)d, height=(int)%(height)d, framerate=(fraction)%(framerate)d/1,'\
+ 'pixel-aspect-ratio=(fraction)1/1, interlaced=(boolean)false'
SCALE = 'ffmpegcolorspace ! videorate ! videoscale ! ffmpegcolorspace'
FEED_SOURCE = 'rtspsrc location=rtsp://%(ip)s ! rtph264depay ! h264parse ! avdec_h264'
MIXER_FORMAT = 'video/x-raw, format=BGRA,'\
+ ' width=%(width)d, height=%(height)d, framerate=%(framerate)d/1, pixel-aspect-ratio=1/1'
SCALE = 'videorate ! videoscale ! videoconvert'
FEED_SINK = 'shmsink socket-path=%(feed_pipe)s shm-size=%(shm_size)d wait-for-connection=0'
OUTPUT_SOURCE = 'shmsrc socket-path=%(mixer_pipe)s do-timestamp=true is-live=true'
SCREEN_OUTPUT = 'videoscale ! video/x-raw-rgb, width=%(screen_width)d, height=%(screen_height)d !'\
+ ' timeoverlay ! ximagesink'
NETWORK_OUTPUT = 'ffmpegcolorspace ! timeoverlay ! x264enc tune="zerolatency" ! mpegtsmux ! tcpserversink host=0.0.0.0 port=%(port)d'
SCREEN_OUTPUT = 'videoscale ! video/x-raw, format=BGRA, width=%(screen_width)d, height=%(screen_height)d !'\
+ 'videoconvert ! timeoverlay ! ximagesink'
NETWORK_OUTPUT = 'videoconvert ! timeoverlay ! x264enc tune="zerolatency" ! mpegtsmux ! tcpserversink host=0.0.0.0 port=%(port)d'

View File

@ -1,9 +1,8 @@
#!/bin/env python2
import pygst
pygst.require('0.10')
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
class Feed(object):
@ -13,23 +12,19 @@ class Feed(object):
self._pipeline = None
self._name = name
def is_running(self):
return self._running
def stop(self):
if not self._running:
return
if self._pipeline <> None:
print "[%s] pipeline stopped" % self._name
self._pipeline.set_state(gst.STATE_NULL)
self._pipeline.set_state(Gst.State.NULL)
if self._thread <> None:
print "[%s] waiting for thread to terminate" % self._name
self._thread.join(2.0)

View File

@ -3,9 +3,9 @@ import os
import threading
from time import sleep
import pygst
pygst.require('0.10')
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
from feed import Feed
@ -25,10 +25,10 @@ class OutputFeed(Feed):
print '[%s] not starting because mixer is not running (pipe is missing)' % self._name
return
print '[%s] is starting' % self._name
self._running = True
self._thread = threading.Thread(target=self._run)
self._thread = threading.Thread(target=self._run)
self._thread.start()
@ -38,24 +38,24 @@ class OutputFeed(Feed):
screen_output = SCREEN_OUTPUT % {'screen_width' : SCREEN_WIDTH, 'screen_height' : SCREEN_HEIGHT}
network_output = NETWORK_OUTPUT % {'port' : OUTPUT_PORT}
pipeline = '%s ! %s ! queue leaky=2 ! tee name=split ! queue leaky=2 ! %s split. ! queue leaky=2 ! %s' % (src,
mixer_format,
pipeline = '%s ! %s ! queue leaky=2 ! tee name=split ! queue leaky=2 ! %s split. ! queue leaky=2 ! %s' % (src,
mixer_format,
screen_output,
network_output)
print pipeline
self._pipeline = gst.parse_launch(pipeline)
self._pipeline = Gst.parse_launch(pipeline)
self._pipeline.set_state(gst.STATE_PLAYING)
self._pipeline.set_state(Gst.State.PLAYING)
print "[%s] is playing" % self._name
bus = self._pipeline.get_bus()
msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE, gst.MESSAGE_ERROR | gst.MESSAGE_EOS)
msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS)
print "[%s] %s" % (self._name, msg.parse_error()[1])
self._pipeline.set_state(gst.STATE_NULL)
self._pipeline.set_state(Gst.State.NULL)
self._running = False
print "[%s] has stopped" % self._name

View File

@ -3,7 +3,10 @@ import os
import sys
import signal
import time
import gobject
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst,GObject
from camerafeed import CameraFeed
from outputfeed import OutputFeed
@ -23,7 +26,8 @@ def handle_sigint(signum, frame):
sys.exit(0)
gobject.threads_init()
GObject.threads_init()
Gst.init(None)
signal.signal(signal.SIGINT, handle_sigint)
for pipe, ip in CAMERA_FEEDS.items():
@ -35,7 +39,7 @@ while os.path.exists(MIXER_PIPE):
for feed in feeds:
if not feed.is_running():
feed.start()
time.sleep(5)
teardown()