I am trying to stream a video from an android phone to my laptop. I ran the gstreamer and it works fine. My problem is with the following code:
[....]
pipeline = gst.parse_launch('rtspsrc name=source latency=0 ! decodebin ! autovideosink')
source = pipeline.get_by_name('source')
source.props.location = "rtsp://128.237.119.100:8086/"
decoder = gst.element_factory_make("decodebin", "decoder")
sink = gst.element_factory_make("autovideosink", "sink")
pipeline.add(source, decoder, sink)
gst.element_link_many(source, decoder, sink)
[...]
I get this error when I run it:
(server.py:2893): GStreamer-WARNING **: Name 'source' is not unique in bin 'pipeline0', not adding
Traceback (most recent call last):
File "server.py", line 27, in <module>
py = pyserver()
File "server.py", line 18, in __init__
pipeline.add(source, decoder, sink)
gst.AddError: Could not add element 'source'
I am new to gstreamer. I have referred to this question to write the code: Playing RTSP with python-gstreamer
Could anyone please point out what I am doing wrong? Why do I get the adderror?
You don't have to add the element source to the pipeline again. It is already added.
From gstreamer gst_pipeline_add_many() documentation:
Adds a NULL-terminated list of elements to a bin.
So it's should be:
gst.element_link_many(source, decoder, sink, NULL);
Related
I am new to GObject , GStreamer , GI etc.
I've mac running high-sierra.
While I am able to run a test audio file successfully as below.
gst-launch-1.0 filesrc location=test.mp3 ! decodebin ! audioconvert ! autoaudiosink
I am not able to simulate same within a python code.
It's returning following error
python ccc.py
<Gst.Message object at 0x10ebb59a8 (GstMessage at 0x7fde5688b740)>
<flags GST_MESSAGE_ERROR of type Gst.MessageType>
(gerror=GLib.Error('Internal data stream error.', 'gst-stream-error-quark', 1), debug='gstbaseparse.c(3611): void gst_base_parse_loop(GstPad *) (): /GstPipeline:pipeline0/GstDecodeBin:decodebin/GstMpegAudioParse:mpegaudioparse0:\nstreaming stopped, reason not-linked (-1)')
Code
#!/usr/bin/python
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GLib, GObject
from gi.repository import Gst as gst
#Initialize Go Objects
GObject.threads_init()
gst.init(None)
# Create the pipeline for our elements.
pipe = gst.Pipeline()
source = gst.ElementFactory.make("filesrc", "file-source")
source.set_property("location", "test.wav")
decoder = gst.ElementFactory.make("decodebin","decodebin")
converter = gst.ElementFactory.make("audioconvert","audioconvert")
audiosink = gst.ElementFactory.make("autoaudiosink", "audiosink")
# Ensure all elements were created successfully.
if (not pipe or not source or not decoder or not audiosink):
print('Not all elements could be created.')
exit(-1)
#Add elements to pipeline
pipe.add(source)
pipe.add(decoder)
pipe.add(converter)
pipe.add(audiosink)
#Link our elements together.
source.link(decoder)
decoder.link(converter)
converter.link(audiosink)
# Set our pipelines state to Playing.
pipe.set_state(gst.State.PLAYING)
# Wait until error or EOS.
bus = pipe.get_bus()
msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE,gst.MessageType.ERROR | gst.MessageType.EOS)
print msg
print msg.type
print msg.parse_error()
# Free resources.
pipe.set_state(gst.State.NULL)
Any pointers? Thanks.
Try using the Gst.parse_launch, to directly input your complete pipeline in the same way as you do in the command line.
Eg:
PIPE = """ filesrc location=test.mp3 ! decodebin ! audioconvert ! autoaudiosink """
And then:
pipeline = Gst.parse_launch(PIPE)
This is much easier than adding it individually and linking them to pipeline.
Using Py2Neo 2.0 and Pycharm Community Edition 4
I'm trying to update a node. First I get the node object, change a node property, bind to the database, and then push the node. I get a slew of errors. Here is the code.
user_node = Graph().find_one('USER',
property_key='email',
property_value='marnee#marnee.com')
user_properties['mission_statement'] = 'New mission statement'
user_node.bind(uri=Graph().uri)
user_node.push()
The node is found, it does have a mission_statement property. The exception seems to happen on .push(). The Graph() uri is good, too.
Below are the errors.
I had been able to do this successfully about a week ago. I have not updated any packages recently.
The really weird part is that if I have a breakpoint and run this in debug mode I do not get any errors and the node is updated successfully.
Traceback (most recent call last):
File "C:/Users/Marnee Dearman/PycharmProjects/AgoraDev/py2neo_2.0_tests/create_rel_int_loc.py", line 27, in <module>
user_node.push()
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\core.py", line 1519, in push
batch.push()
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\push.py", line 73, in push
self.graph.batch.run(self)
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 99, in run
response = self.post(batch)
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 88, in post
data.append(dict(job, id=i))
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 232, in __iter__
yield "to", self.target.uri_string
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\batch\core.py", line 180, in uri_string
uri_string = self.entity.ref
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\core.py", line 1421, in ref
return "node/%s" % self._id
File "C:\Users\Marnee Dearman\PycharmProjects\VirtualEnvs\AgoraDev\lib\site-packages\py2neo\core.py", line 1412, in _id
self.__id = int(self.uri.path.segments[-1])
ValueError: invalid literal for int() with base 10: ''
Using Nigel's advice below, I got this to work. It was a usage error on my part:
user_node = Graph().find_one('USER',
property_key='email',
property_value='marnee#email.com')
user_node.properties['mission_statement'] = 'New mission statement'
user_node.push()
There are a couple of problems with your code so I will try to clarify the correct usage of these methods.
The bind method is used to connect a local entity (in this case, Node) to a corresponding remote equivalent. You should generally never need to use this method explicitly as entities are typically bound automatically on creation or retrieval. In your case, the find_one method does exactly this and constructs a client-side node that is bound to a corresponding server-side node; an explicit bind is not required.
The second issue is with your usage of bind. The URI taken by this method is that of a specific remote resource. You have passed the URI of the Graph itself (probably http://localhost:7474/db/data/) instead of that of the Node (such as http://localhost:7474/db/data/node/2345). The actual error that you see is caused by py2neo attempting to strip the ID from the URI and failing.
The simple solution is to remove the bind call.
Im a biologist and new to pywinauto, i wrote a code to open an input file in HYPHY application using pywinauto, when i run my code line by line in command line it works fine but when i run the code as a batch file it gives the following error.
Traceback (most recent call last):
File "C:\Users\Masyh\Desktop\autowin_test.py", line 8, in <module>
w_handle = pywinauto.findwindows.find_windows(title=u' Please select a batch file to run:', class_name='#32770')[0]
IndexError: list index out of range
the code is:
import pywinauto
pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'HYPHY Console', class_name='HYPHY')[0]
window = pwa_app.window_(handle=w_handle)
window.SetFocus()
window.MenuItem(u'&File->&Open->Open &Batch File\tCtrl+O').Click()
w_handle = pywinauto.findwindows.find_windows(title=u' Please select a batch file to run:', class_name='#32770')[0]
window = pwa_app.window_(handle=w_handle)
window.SetFocus()
ctrl = window['Edit']
ctrl.Click()
ctrl.TypeKeys('brown.nuc')
ctrl=window['&open']
ctrl.Click()
i guess the problem is that the window which gets the input(#'please select a batch file menue') is not open at the beginning and the first part of the code opens it but python looks for it from the beginning and cant find it.
i really appreciate any suggestions how to solve this.
It looks like the window does not exist when the checking is performed. You should wait for a some time for window is opened.
try the next construction:
a_check = lambda: pywinauto.findwindows.find_windows(title=u' Please select a batch file to run:', class_name='#32770')[0]
try:
w_handle = pywinauto.timings.WaitUntilPasses(timeout=10, retry_interval=1, a_check)
except:
print('Something went wrong')
Also, your problem can be caused by the window has extra attributes/state. For example, inisible.
Use allowed argumens from find_windows to handle such cases, here the arguments list with defaul values:
pywinauto.findwindows.find_windows(class_name=None,class_name_re=None, parent=None, process=None, title=None, title_re=None, top_level_only=True, visible_only=True, enabled_only=False, best_match=None, handle=None, ctrl_index=None, predicate_func=None, active_only=False, control_id=None)
I was running my script and I stumbled upon on this error
WARNING *** file size (24627) not 512 + multiple of sector size (512)
WARNING *** OLE2 inconsistency: SSCS size is 0 but SSAT size is non-zero
Traceback (most recent call last):
File "C:\Email Attachments\whatever.py", line 20, in <module>
main()
File "C:\Email Attachments\whatever.py", line 17, in main
csv_from_excel()
File "C:\Email Attachments\whatever.py", line 7, in csv_from_excel
sh = wb.sheet_by_name('B2B_REP_YLD_100_D_SQ.rpt')
File "C:\Python27\lib\site-packages\xlrd\book.py", line 442, in sheet_by_name
return self.sheet_by_index(sheetx)
File "C:\Python27\lib\site-packages\xlrd\book.py", line 432, in sheet_by_index
return self._sheet_list[sheetx] or self.get_sheet(sheetx)
File "C:\Python27\lib\site-packages\xlrd\book.py", line 696, in get_sheet
sh.read(self)
File "C:\Python27\lib\site-packages\xlrd\sheet.py", line 1055, in read
dim_tuple = local_unpack('<ixxH', data[4:12])
error: unpack requires a string argument of length 8
I was trying to process this excel file.
https://drive.google.com/file/d/0B12NevhOGQGRMkRVdExuYjFveDQ/edit?usp=sharing
One solution that I found is that I have to open manually the spreadsheet, save it, then close it before I run my script of converting .xls to .csv. I find this solution a bit cumbersome and clunky.
This kind of spreadsheet is saved daily in my drive via an Outlook Macro. Unprocessed data is increasing that's why I turned into scripting to ease the job.
Who made the Outlook macro that's dumping this file? xlrd uses byte level unpacking to read in the Excel file, and is failing to read a field in this excel file. There are ways to follow where its failing, but none to automatically recover from this type of error.
The erroneous data seems to be at data[4:12] of a specific frame (we'll see later), which should be a bytestring that's parsed as such:
one integer (i)
2 pad bytes (xx)
unsigned short 2 byte integer (H).
You can set xlrd to DEBUG mode, which will show you which bytes its parsing, and exactly where in the file there is an error:
import xlrd
xlrd.DEBUG = 2
workbook = xlrd.open_workbook(u'/home/sparker/Downloads/20131117_040934_B2B_REP_YLD_100_D_LT.xls')
Here's the results, slightly trimmed down for the sake of SO:
parse_globals: record code is 0x0293
parse_globals: record code is 0x0293
parse_globals: record code is 0x0085
CODEPAGE: codepage 1200 -> encoding 'utf_16_le'
BOUNDSHEET: bv=80 data '\xfd\x04\x00\x00\x00\x00\x18\x00B2B_REP_YLD_100_D_SQ.rpt'
BOUNDSHEET: inx=0 vis=0 sheet_name=u'B2B_REP_YLD_100_D_SQ.rpt' abs_posn=1277 sheet_type=0x00
parse_globals: record code is 0x000a
GET_SHEETS: [u'B2B_REP_YLD_100_D_SQ.rpt'] [1277]
GET_SHEETS: sheetno = 0 [u'B2B_REP_YLD_100_D_SQ.rpt'] [1277]
reqd: 0x0010
getbof(): data='\x00\x06\x10\x00\xbb\r\xcc\x07\x00\x00\x00\x00\x06\x00\x00\x00'
getbof(): op=0x0809 version2=0x0600 streamtype=0x0010
getbof(): BOF found at offset 1277; savpos=1277
BOF: op=0x0809 vers=0x0600 stream=0x0010 buildid=3515 buildyr=1996 -> BIFF80
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.4-x86_64/egg/xlrd/__init__.py", line 457, in open_workbook
File "build/bdist.macosx-10.4-x86_64/egg/xlrd/__init__.py", line 1007, in get_sheets
File "build/bdist.macosx-10.4-x86_64/egg/xlrd/__init__.py", line 998, in get_sheet
File "build/bdist.macosx-10.4-x86_64/egg/xlrd/sheet.py", line 864, in read
struct.error: unpack requires a string argument of length 8
Specifically, you can see that it parses the name of the workbook named u'B2B_REP_YLD_100_D_SQ.rpt.
Lets check the source code. The traceback throws an error here where we can see from the parent loop that we're trying to parse the XL_DIMENSION and XL_DIMENSION2 values. These directly correspond to the shape of the Excel Sheet.
And that's where there's a problem in your workbook. It's not being made correctly. So, back to my original question, who made the excel macro? It needs to be fixed. But that's for another SO question, some other time.
hi im trying to watermark a pdf fileusing pypdf2 though i get this error i cant figure out what goes wrong.
i get the following error:
Traceback (most recent call last): File "test.py", line 13, in <module>
page.mergePage(watermark.getPage(0)) File "C:\Python27\site-packages\PyPDF2\pdf.py", line 1594, in mergePage
self._mergePage(page2) File "C:\Python27\site-packages\PyPDF2\pdf.py", line 1651, in _mergePage
page2Content, rename, self.pdf) File "C:Python27\site-packages\PyPDF2\pdf.py", line 1547, in
_contentStreamRename
op = operands[i] KeyError: 0
using python 2.7.6 with pypdf2 1.19 on windows 32bit.
hopefully someone can tell me what i do wrong.
my python file:
from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
input = PdfFileReader(open("test.pdf", "rb"))
watermark = PdfFileReader(open("watermark.pdf", "rb"))
# print how many pages input1 has:
print("test.pdf has %d pages." % input.getNumPages())
print("watermark.pdf has %d pages." % watermark.getNumPages())
# add page 0 from input, but first add a watermark from another PDF:
page = input.getPage(0)
page.mergePage(watermark.getPage(0))
output.addPage(page)
# finally, write "output" to document-output.pdf
outputStream = file("outputs.pdf", "wb")
output.write(outputStream)
outputStream.close()
Try writing to a StringIO object instead of a disk file. So, replace this:
outputStream = file("outputs.pdf", "wb")
output.write(outputStream)
outputStream.close()
with this:
outputStream = StringIO.StringIO()
output.write(outputStream) #write merged output to the StringIO object
outputStream.close()
If above code works, then you might be having file writing permission issues. For reference, look at the PyPDF working example in my article.
I encountered this error when attempting to use PyPDF2 to merge in a page which had been generated by reportlab, which used an inline image canvas.drawInlineImage(...), which stores the image in the object stream of the PDF. Other PDFs that use a similar technique for images might be affected in the same way -- effectively, the content stream of the PDF has a data object thrown into it where PyPDF2 doesn't expect it.
If you're able to, a solution can be to re-generate the source pdf, but to not use inline content-stream-stored images -- e.g. generate with canvas.drawImage(...) in reportlab.
Here's an issue about this on PyPDF2.