Skip to content

Commit

Permalink
add optional perspective transform
Browse files Browse the repository at this point in the history
  • Loading branch information
floe committed Jan 15, 2022
1 parent 808ce7a commit 7eb181b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions gst_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def connect_bus(msgtype, callback, *args):
bus.connect(msgtype, callback, *args)

# test sources as stream placeholders
def add_test_sources(frontdev="",surfdev="",fake=False,bgcol=0xFF00FF00,wave="ticks"):
def add_test_sources(frontdev="",surfdev="",fake=False,bgcol=0xFF00FF00,wave="ticks",perspective=None):

if fake:
frontsrc = "videotestsrc is-live=true pattern=smpte ! timeoverlay" if frontdev == "" else frontdev
Expand All @@ -136,6 +136,9 @@ def add_test_sources(frontdev="",surfdev="",fake=False,bgcol=0xFF00FF00,wave="ti
surfsrc = "v4l2src do-timestamp=true device="+surfdev+" ! videorate ! videoconvert"
audiosrc = "alsasrc do-timestamp=true" # "audiorate ! audioconvert"

# FIXME still a bit hackish, maybe solveable without double videoconvert?
vc = None if perspective == None else new_element("videoconvert")

logging.debug(" Front Source: "+frontsrc)
logging.debug("Surface Source: "+surfsrc)
logging.debug(" Audio Source: "+audiosrc)
Expand All @@ -145,7 +148,7 @@ def add_test_sources(frontdev="",surfdev="",fake=False,bgcol=0xFF00FF00,wave="ti
new_element("tee",{"allow-not-linked":True},"fronttestsource")
])

add_and_link([ Gst.parse_bin_from_description( surfsrc, True ),
add_and_link([ Gst.parse_bin_from_description( surfsrc, True ), perspective, vc, # <-- NOTE
new_element("capsfilter",{"caps":Gst.Caps.from_string("video/x-raw,format=YV12,width=1280,height=720,framerate=15/1")}),
new_element("tee",{"allow-not-linked":True},"surfacetestsource")
])
Expand Down
9 changes: 8 additions & 1 deletion webrtc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def on_element_added(thebin, element):
parser.add_argument("-t","--target", help="server to connect to (%(default)s)", default="127.0.0.1")
parser.add_argument("-f","--front", help="front image source (device or pipeline)",default="" )
parser.add_argument("-s","--surface",help="surface image source (device or pipeline)",default="" )
parser.add_argument("-p","--perspective",help="perspective (9 floats: \"1,0,0,...\")",default="" )

args = parser.parse_args()
print("Option",args,"\n")
Expand All @@ -74,7 +75,13 @@ def on_element_added(thebin, element):
if not args.fake and (args.front == "" or args.surface == ""):
logging.warning("Need to either specify --fake for test sources, or -f/-s for source devices/pipelines.")

add_test_sources(args.front,args.surface,args.fake)
if args.perspective != "":
params = [ float(f) for f in args.perspective.split(",") ]
pt = new_element("perspective",{"matrix":params})
else:
pt = None

add_test_sources(args.front,args.surface,args.fake,perspective=pt)

session = Soup.Session()
session.set_property("ssl-strict", False)
Expand Down

0 comments on commit 7eb181b

Please sign in to comment.