Active Topics

 



Notices


Reply
Thread Tools
Posts: 62 | Thanked: 6 times | Joined on Jun 2010 @ Poland
#1
Hello!
I want to develop "blackbox" app for Maemo - like Camdrive for n9.
I need help with code writing in python.
I have all code's but i don't know how to put it together, and need help.
In attachment a proof of GUI.
Code:
Assumptions:
-No options - the simplest as possible
-10 films of 10 minutes each - How to shorten the code to not prescribe 10 times the same?
-No red light when recording - how?
-Only 2 buttons Rec and Stop
-GPS location, time, date and speed must be recorded too.
Here are codes:
Recording
Code:
import gst
import time

liczba = open('czas').read() 
while 1:


	bin = gst.element_factory_make("camerabin")
	bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
	bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
	bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))
	bin.set_state(gst.STATE_PLAYING)
	bin.set_property("filename", "test.mp4")
	bin.set_property("mode",1)
	#starts recording
	bin.emit("user-start")




	print "recording"
	time.sleep(float(liczba)) 
	print "stop"
	
	# stops recording
	bin.emit("user-stop")
	bin.set_state(gst.STATE_PAUSED)
	bin.set_state(gst.STATE_NULL) 


	time.sleep(1)

	bin = gst.element_factory_make("camerabin")
	bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
	bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
	bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))
	bin.set_state(gst.STATE_PLAYING)
	bin.set_property("filename", "test1.mp4")
	bin.set_property("mode",1)
	#starts recording
	bin.emit("user-start")

	print "recording"
	time.sleep(float(liczba))
	print "stop"

	# stops recording
	bin.emit("user-stop")
	bin.set_state(gst.STATE_PAUSED)
	bin.set_state(gst.STATE_NULL)
Date, time, GPS location and speed
Code:
import location
import gobject
import time
import datetime

def on_error(control, error, data):
    print "location error: %d... quitting" % error
    data.quit()

def on_changed(device, data):
    if not device:
        print "no device"
        return
    if device.fix:
        if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
            print "[lat = %f, long = %f]" % device.fix[4:6]
            #data.stop()
        else:
            print "no fix 1"
    else:
        print "no fix"

def on_stop(control, data):
    print "quitting"
    data.quit()

def start_location(data):
    data.start()
    return False

def get_speed(device, data):
    if not device:
        return
    if device.fix:
        if device.fix[1] & location.GPS_DEVICE_SPEED_SET:
            print "[Speed %s Km/h" % device.fix[11],
            print "(%s)]"% device.fix[12],
            #data.stop()

def get_time(device, data):
    if not device:
        return
    if device.fix:
        if device.fix[1] & location.GPS_DEVICE_TIME_SET:
            #print "[Time %s]" % device.fix[2],
            #print time.gmtime(1268705044.0)
            #print time.strftime('%X %x %Z', 1268705044.0)
            print datetime.datetime.fromtimestamp(device.fix[2]),
            #data.stop()
        else:
            print "no time"

#i = 0
loop = gobject.MainLoop()
control = location.GPSDControl.get_default()
device = location.GPSDevice()
control.set_properties(preferred_method=location.METHOD_AGNSS,
                       preferred_interval=location.INTERVAL_1S)

control.connect("error-verbose", on_error, loop)
device.connect("changed", get_time, control)
device.connect("changed", get_speed, control)
device.connect("changed", on_changed, control)
control.connect("gpsd-stopped", on_stop, loop)

gobject.idle_add(start_location, control)

loop.run()
GUI window.py
Code:

# Created: Sun Dec 01 20:24:50 2013
#      by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(800, 480)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.btnStop = QtGui.QPushButton(self.centralwidget)
        self.btnStop.setGeometry(QtCore.QRect(150, 350, 91, 71))
        self.btnStop.setObjectName(_fromUtf8("btnStop"))
        self.btnRec = QtGui.QPushButton(self.centralwidget)
        self.btnRec.setGeometry(QtCore.QRect(20, 350, 91, 71))
        self.btnRec.setObjectName(_fromUtf8("btnRec"))
        self.dane = QtGui.QLabel(self.centralwidget)
        self.dane.setGeometry(QtCore.QRect(20, 20, 771, 31))
        self.dane.setObjectName(_fromUtf8("dane"))
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MaeBox", None))
        self.btnStop.setText(_translate("MainWindow", "STOP", None))
        self.btnRec.setText(_translate("MainWindow", "REC", None))
        self.dane.setText(_translate("MainWindow", "Dane", None))
Main code - main.py
Code:

import sys
from PyQt4 import QtGui
from window import Ui_MainWindow

class Main(QtGui.QMainWindow):

        
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.btnRec.clicked.connect(self.btnRec_Clicked)
        self.ui.btnStop.clicked.connect(self.btnStop_Clicked)

        
    def btnRec_Clicked(self):
        self.ui.dane.setText("DANE GPS, GODZINA I DATA oraz START NAGRYWANIA")
        
    def btnStop_Clicked(self):
        self.ui.dane.setText("")

        
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_())
I'm a newbie, so please help how to put this code together and to satisfy all the assumptions.

Regards
Marcin
ps.
file "czas" must be created and filled with seconds of film for 10 minutes 600 seconds.
Attached Images
 
__________________
Maemo Meego Maego!
 
Reply

Tags
camdrive, camera, gstreamer, pyqt4, python


 
Forum Jump


All times are GMT. The time now is 22:09.