Addon for Picamera (video)
#1
I would like to basically make a dash cam. I would like to have an addon that is maybe gui based if possible. I installed everything found here:
https://www.raspberrypi.org/documentatio.../README.md

Considering I have never built an add-on before, could you guys help me please? I want it to be enabled when the pi is on, and maybe record 4gb then overwrite it after 4gb is reached. Huh
Reply
#2
Well, im giving this a shot. Im fumbleing around with code and trying to get somewhere. So far I have"hello world".
Here is the beginning code:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="picam.test" name="picamera" version="0.0.1" provider-name="Jon">
    <requires>
        <import addon="xbmc.python" version="2.25.0"/>
import picamera
  camera = picamera.PiCamera()
camera.capture('image.jpg')
    </requires>
    <extension point="xbmc.python.script" library="main.py">
        <provides>video</provides>
    </extension>
    <extension point="xbmc.addon.metadata">
        <summary lang="en_GB">Dash camera for vehicles</summary>
        <description lang="en_GB"></description>
        <language></language>
        <platform>all</platform>
        <license>Apache-2.0</license>
        <forum></forum>
        <website></website>
        <email>[email protected]</email>
        <source></source>
        <news></news>
        <disclaimer></disclaimer>
        <assets>
            <icon>resources/icon.png</icon>
            <fanart>resources/fanart.jpg</fanart>
        </assets>
    </extension>
</addon>

Any insight is greatly appreciated.
Reply
#3
Code:
<import picamera
  camera = picamera.PiCamera()>

I don't know a lot about creating addons, but this is definitely not valid XML. That's why you're getting the parse error. XML is a language for storing data. Addon.xml only holds information about your addon. Addon.py is where your code goes. Take a look here for addon structure, and really look over the whole addon development section before creating your addon.
Reply
#4
You cannot import and run methods from the addon.xml...
calling camera = picamera.PiCamera() alone will not yield results.

First learn how to create a basic script with a correct addon.xml structure. Once you are able to open a custom window, your next step will be to capture pi images and setImage a window control.

http://kodi.wiki/view/addon.xml
http://kodi.wiki/view/HOW-TO:Write_Pytho...BMC#Window
https://codedocs.xyz/xbmc/xbmc/group__py...116a784ac5
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#5
Someone correct me if I'm wrong (it's perfectly possible that I don't understand this situation correctly) but I wouldn't have thought the picamera module would be available to Kodi's python interpreter.

Fortunately, the module is pure python and so could, presumably, just be copied into the addon folder (or someone could make a script.module.picamera).
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#6
Sorry, ablues10, just realised it was you.

Assuming you're doing this on your LibreELEC system, I think the picamera module may be part of the PiTools addon that you've already got installed. If so, you'd just need to include the same import lines in your script before trying to import picamera:
Code:
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import picamera
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#7
If picamera is pure python and all its dependencies are met, there should be no reason why it can't be used... Either as a direct import within a single script or as a module for broader use.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#8
(2017-06-22, 14:23)el_Paraguayo Wrote: Sorry, ablues10, just realised it was you.

Assuming you're doing this on your LibreELEC system, I think the picamera module may be part of the PiTools addon that you've already got installed. If so, you'd just need to include the same import lines in your script before trying to import picamera:
Code:
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import picamera


I got this:

Quote: ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.IOError'>
Error Contents: [Errno 30] Read-only file system: 'image.jpg'
Traceback (most recent call last):
File "/storage/.kodi/addons/picam.test/main.py", line 4, in <module>
from resources.lib import script
File "/storage/.kodi/addons/picam.test/resources/lib/script.py", line 8, in <module>
camera.capture('image.jpg')
File "/storage/.kodi/addons/virtual.rpi-tools/lib/picamera/camera.py", line 1570, in capture
encoder.start(output)
File "/storage/.kodi/addons/virtual.rpi-tools/lib/picamera/encoders.py", line 1543, in start
super(PiCookedOneImageEncoder, self).start(output)
File "/storage/.kodi/addons/virtual.rpi-tools/lib/picamera/encoders.py", line 819, in start
self._open_output(output)
File "/storage/.kodi/addons/virtual.rpi-tools/lib/picamera/encoders.py", line 774, in _open_output
output = io.open(output, 'wb', buffering=65536)
IOError: [Errno 30] Read-only file system: 'image.jpg'
-->End of Python script error report<--
Reply
#9
You're going to need to use a path where you have write access. For Kodi, this should be the addon profile folder.

You'll need this at the top of your script:
Code:
import xbmc, xbmcaddon
import os

PROFILE_PATH = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')).decode('utf-8')

IMAGE_FILE = os.path.join(PROFILE_PATH, "image.jpg")

# your other code...

camera.capture(IMAGE_FILE)
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#10
(2017-06-22, 15:59)el_Paraguayo Wrote: You're going to need to use a path where you have write access. For Kodi, this should be the addon profile folder.

You'll need this at the top of your script:
Code:
import xbmc, xbmcaddon
import os

PROFILE_PATH = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')).decode('utf-8')

IMAGE_FILE = os.path.join(PROFILE_PATH, "image.jpg")

# your other code...

camera.capture(IMAGE_FILE)

What about video. I have the camera working but I cant exit it lol. I want to be able to record video until 2gb or 2hr of video is filled then record over the 2gb again and again.
Reply
#11
That's a question that might be better answered on the raspberry pi forum.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#12
(2017-06-22, 16:34)el_Paraguayo Wrote: That's a question that might be better answered on the raspberry pi forum.

With as much as you have helped me out, I want to buy you a beer. Got a paypal acct?
Reply
#13
Don't worry about it. I don't need the cash. I help out on the forums (this one and the Raspberry Pi one) because it's a good distraction from work.

Save your beer money and, once you get your code working, buy yourself the beer and enjoy the taste of success!
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#14
(2017-06-22, 19:35)el_Paraguayo Wrote: Don't worry about it. I don't need the cash. I help out on the forums (this one and the Raspberry Pi one) because it's a good distraction from work.

Save your beer money and, once you get your code working, buy yourself the beer and enjoy the taste of success!

I tried to post at Piforums with no response. Do you have any idea what happened here?

Code:
# -*- coding: utf-8 -*-
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import picamera
from time import sleep

# User inputs selected data
filename = raw_input("Give your file a name: ")
length = raw_input("How long would you like to record: ")

# Camera is on for a specified time
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.framrate = (60)
camera.start_recording(filename + ".h264")
time.sleep(float(length))
camera.stop_recording()

# Save video in a specified folder
save_path = '/home/pi/picamera'
completed_video = os.path.join(save_path, filename)

from resources.lib import kodiutils
from resources.lib import kodilogging
import logging
import xbmcaddon
import xbmcgui
ADDON = xbmcaddon.Addon()
logger = logging.getLogger(ADDON.getAddonInfo('id'))


# Put your code here, this is just an example showing
# a textbox as soon as this addon gets called
def show_dialog():
    addon_name = ADDON.getAddonInfo('name')

    line1 = "Hello World!"

    xbmcgui.Dialog().ok(addon_name, line1)

https://pastebin.com/sgq8Pjgp
Reply
#15
I don't see how you could use raw_input in a kodi addon to get user input.

I think you would need to use an input dialog. See this: http://mirrors.kodi.tv/docs/python-docs/...alog-input
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Addon for Picamera (video)00