Addon for Picamera (video)
#16
I can't see why you need user input for the filename at all. Creating a file with a name like "Dashcam-2017-06-30-190525.264" is programmatically simple, logical and pretty typical in this situation.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#17
Well, yes, that would be even easier and, more importantly, safer. You don't want to be typing if you're driving!!
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#18
(2017-06-30, 09:07)nickr Wrote: I can't see why you need user input for the filename at all. Creating a file with a name like "Dashcam-2017-06-30-190525.264" is programmatically simple, logical and pretty typical in this situation.

(2017-06-30, 10:47)el_Paraguayo Wrote: Well, yes, that would be even easier and, more importantly, safer. You don't want to be typing if you're driving!!


https://pastebin.com/twuRV2JW



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
# Camera is on for a specified time
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.framrate = (60)
camera.start_recording("Dashcam-2017-06-30-190525H.264")
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)

How do I specify the type?
Reply
#19
https://pastebin.com/CS0YqF0K

I had the filetype named wrong. My new issue is I only have read access, no write access.
Reply
#20
So apparently I need to mount a usb (which I want to store the videos on) I have a UUID for my drive @ 38D0-F8E6. How do I do this in a python script?
Reply
#21
Does LibreElec automount USBs (and does it mount them with read/write permissions)? If so there's a "findmnt" command which may help (I don't know if it's available in LibreElec).


This command:
Code:
findmnt -rn -S UID=38D0-F8E6 -o TARGET
would output the mount point.

You could use this in a python script as follows:
Code:
import subprocess

UID = "38D0-F8E6"
cmd = ["findmnt", "-rn", -"S", "UID={0}".format(UID), "-o", "TARGET"]

try:
    mount_point = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    # do something with mount_point

except subprocess.CalledProcessError:
    # There was an error - command exited with non-zero code
    # Could mean the USB wasn't mounted

One question, is your UID correct? I'd expect it to be longer than that.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#22
(2017-06-30, 17:38)el_Paraguayo Wrote: Does LibreElec automount USBs (and does it mount them with read/write permissions)? If so there's a "findmnt" command which may help (I don't know if it's available in LibreElec).


This command:
Code:
findmnt -rn -S UID=38D0-F8E6 -o TARGET
would output the mount point.

You could use this in a python script as follows:
Code:
import subprocess

UID = "38D0-F8E6"
cmd = ["findmnt", "-rn", -"S", "UID={0}".format(UID), "-o", "TARGET"]

try:
    mount_point = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    # do something with mount_point

except subprocess.CalledProcessError:
    # There was an error - command exited with non-zero code
    # Could mean the USB wasn't mounted

One question, is your UID correct? I'd expect it to be longer than that.


I ran:
cat /proc/mounts


I got /dev/sda /var/media/16GB\040FLASH vfat rw,nosuid,nodev,noexec,noatime,fmask=0133,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0

Here is the UUID list: https://pastebin.com/Kfx0Qa5r
Reply
#23
Can you try running the findmnt command? This would be neater than parsing /proc/mounts directly.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#24
(2017-06-30, 19:16)el_Paraguayo Wrote: Can you try running the findmnt command? This would be neater than parsing /proc/mounts directly.

It says "not found"
Reply
#25
I ran:

/$ lsusb
This is what I got. I assume its the first one.
Bus 001 Device 005: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 001 Device 004: ID 045e:00e1 Microsoft Corp. Wireless Laser Mouse 6000 Receiver
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Reply
#26
Find UUIDs with blkid

Find mount points with mount
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#27
(2017-06-30, 19:16)el_Paraguayo Wrote: Can you try running the findmnt command? This would be neater than parsing /proc/mounts directly.

(2017-07-01, 00:09)nickr Wrote: Find UUIDs with blkid

Find mount points with mount

Here is the one with blkid:

/dev/sda1: LABEL="Samsung USB" UUID="D09F-09C4" TYPE="vfat" PARTUUID="c3072e18-01"


Here is the one with mount:

/dev/sda1 on /var/media/Samsung USB type vfat (rw,nosuid,nodev,noexec,noatime,fmask=0133,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)


Here is the error report using BOTH the UUID and PARTUUID:
https://pastebin.com/bGP8Gb70
Reply
#28
findmnt does not exist on libreelec.

You now know where your drive is mounted don't you?

/var/media/Samsung USB

Don't forget to make sure you quote that properly, as the space between Samsung and USB will cause you problems otherwise.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#29
So my code would look like this:
Quote:# -*- 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
# Camera is on for a specified time
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.framrate = (60)
camera.start_recording("Dashcam-2017-06-30-190525H.264")
time.sleep(float(length))
camera.stop_recording()

# Save video in a specified folder
save_path = '/var/media/Samsung USB'
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)

The reason I thought I needed to mount it was because of the R/W permissions. I will try the script in the morning.
Reply
#30
It is mounted rw, you can see that from the output of the mount command.

I think this may be better version of your code, although I am no expert and haven't tried it.

My changes: put your imports etc all at the top of the file. That seems to be the python way, I see no reason to depart from the norm.

Name the recording file according to current date and time.

Record the file direct to the USB device, otherwise you just have to shift it, and it may fill up the limited space on an SD card. Also, the less you write to your SD card, the better.

Code:
# -*- coding: utf-8 -*-
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import picamera
from time import sleep,strftime,localtime
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'))

# Save video in a specified folder
save_path = '/var/media/Samsung USB'
filename = "Dashcam-" + strftime("%Y%m%d%H%M"),localtime + ".264"

completed_video = os.path.join(save_path, filename)

# User inputs selected data
# Camera is on for a specified time
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.framerate = (60)
camera.start_recording(completed_video)
time.sleep(float(length))
camera.stop_recording()
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply

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