Created
August 8, 2017 13:54
-
-
Save half2me/2e66bac31c4d5562c714324dbd2ab67e to your computer and use it in GitHub Desktop.
Example FTP Sink for Gstreamer1.0 in Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Make sure you have py-gst installed (on OSX: brew install py-gst) | |
# export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:$PWD/ # this will be the folder containing the "python" directory | |
# You must put this script in a directory called "python" for this to work :) | |
# | |
# Example usage: | |
# GST_DEBUG=python:4 gst-launch-1.0 videotestsrc ! jpegenc ! ftpsink | |
import ftplib | |
import io | |
import random | |
import string | |
import gi | |
gi.require_version('GstBase', '1.0') | |
from gi.repository import Gst, GObject, GstBase | |
Gst.init(None) | |
class Ftpsink(GstBase.BaseSink): | |
__gstmetadata__ = ('FTP Sink', 'FTP Sink', | |
'Send everything to FTP server', 'Candid Dev team') | |
__gsttemplates__ = (Gst.PadTemplate.new("sink", | |
Gst.PadDirection.SINK, | |
Gst.PadPresence.ALWAYS, | |
Gst.Caps.new_any())) | |
def do_render(self, buffer): | |
global ftp | |
(result, mapinfo) = buffer.map(Gst.MapFlags.READ) | |
assert result | |
try: | |
data = io.BytesIO(mapinfo.data) | |
ftp.storbinary('STOR ' + ''.join(random.choices(string.ascii_lowercase + string.digits, k=100)) + '.jpg', data) | |
finally: | |
buffer.unmap(mapinfo) | |
# global ftp | |
# pbuffer = io.BytesIO(buffer) | |
# ftp.storbinary('STOR binary', pbuffer) | |
return Gst.FlowReturn.OK | |
GObject.type_register(Ftpsink) | |
__gstelementfactory__ = ("ftpsink", Gst.Rank.NONE, Ftpsink) # Here you specify the name of your plugin | |
ftp = ftplib.FTP("192.168.1.60") | |
ftp.login("username", "password") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment