RenderCapture need help
#31
PHP Code:
class MyPlayer(xbmc.Player):
    
duration 0
    playingvideo 
False
    playlistlen 
0
    movie 
False

    def __init__
(self):
        
xbmclog('Kodi Hue: In MyPlayer.__init__()')
        
xbmc.Player.__init__(self)

    
def onPlayBackStarted(self):
        
xbmclog('Kodi Hue: In MyPlayer.onPlayBackStarted()')
        
playlist xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        
self.playlistlen playlist.size()
        
self.playingvideo True
        self
.duration self.getTotalTime()
        
state_changed("started"self.duration)

    
def onPlayBackPaused(self):
        
xbmclog('Kodi Hue: In MyPlayer.onPlayBackPaused()')
        
state_changed("paused"self.duration)
        if 
self.isPlayingVideo():
            
self.playingvideo False

    def onPlayBackResumed
(self):
        
xbmclog('Kodi Hue: In MyPlayer.onPlayBackResume()')
        
state_changed("resumed"self.duration)
        if 
self.isPlayingVideo():
            
self.playingvideo True
            
if self.duration == 0:
                
self.duration self.getTotalTime()

    
def onPlayBackStopped(self):
        
xbmclog('Kodi Hue: In MyPlayer.onPlayBackStopped()')
        
state_changed("stopped"self.duration)
        
self.playingvideo False
        self
.playlistlen 0

    def onPlayBackEnded
(self):
        
xbmclog('Kodi Hue: In MyPlayer.onPlayBackEnded()')
        
# If there are upcoming plays, ignore
        
if self.playlistpos self.playlistlen-1:
            return

        
self.playingvideo False
        state_changed
("stopped"self.duration

PHP Code:
def run():
    
player MyPlayer()
    if 
player is None:
        
xbmclog('Kodi Hue: In run() could not instantiate player')
        return

    while 
not monitor.abortRequested():
        if 
len(hue.ambilight_controller.lights) and not ev.is_set():
            
startReadOut False
            vals 
= {}
            
# live tv does not trigger playbackstart
            
if player.isPlayingVideo() and not player.playingvideo:
                
player.playingvideo True

                state_changed
("started"player.getTotalTime())
                continue
            if 
player.playingvideo:  # only if there's actually video
                
try:
                    
vals capture.getImage(200)
                    if 
len(vals) > and player.playingvideo:
                        
startReadOut True
                    
if startReadOut:
                        
screen image.Screenshot(
                            
capture.getImage())
                        
hsv_ratios screen.spectrum_hsv(
                            
screen.pixels,
                            
hue.settings.ambilight_threshold_value,
                            
hue.settings.ambilight_threshold_saturation,
                            
hue.settings.color_bias,
                            
len(hue.ambilight_controller.lights)
                        )
                        for 
i in range(len(hue.ambilight_controller.lights)):
                            
algorithm.transition_colorspace(
                                
huehue.ambilight_controller.lights.values()[i], hsv_ratios[i], )
                
except ZeroDivisionError:
                    
pass

        
if monitor.waitForAbort(0.1):
            
xbmclog('Kodi Hue: In run() deleting player')
            
del player  # might help with slow exit. 


Just a few questions to be sure I am thinking of this the right way.
I have to have a myplayer class so that the script know when it has a video so that it will not null out?
PHP Code:
for vals capture.getimage(200

# where is the 200 coming from is this the default control for the player?

once I get to screen = image.Screenshot(capture.getImage())

#could I then do
PHP Code:
screenshot Image.open(screen)
 
screenshot.save(os.path.join(addondatapath,"screenshot_test"


Or do I need to do some more reading... right now I just want to be abot to see the full image so I know it is working... after that I will then try to add the rest of the parts
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#32
The above looks a little bulkier then I would have expected... I pictured a simple while loop, that checked isplaying and whatever property condition you want your skin to trigger when its time to capture the screen.

below pseudocode

Code:
while xbmc.monitor().waitingforabort():
       if xbmc.player().isplaying() and getprop('capture') == "true":
           dosomething()
       if xbmc.monitor().timetowait(1):
           break


def dosomething():
     #capture and calculate majority color, set diffuse property for skin to use

If I were you'd I start clean, don't try to build off the hue script, since only a small part of it does what you want... it maybe a little confusing to follow all of the imports and functions.

Make a checklist:
1. create a loop as described above.
2. work on dosomething, get a screencapture...
3. work on foobar, get pixel info from image in memory.

BTW you don't want to save the screenshot, this will tax the system i/o and is not needed... You can work with the byte array in memory.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#33
Just so I can some what understand a byte arry better is there a way to get capture it and display it back into Kodi with out doing anything 2 it? Is the byte arry still a image of just a bunch of number... That is the part I can't wrap my minD around yet . Sorry I know this is probably trivial​ to you. And I really and try to look things up about bytearry and I do see there is alot can be done with it... But most examples are using a image saved on a drive somewhere and with this it an actual video so that has me off a bit.
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#34
(2017-06-08, 08:44)smitchell6879 Wrote: Just so I can some what understand a byte arry better is there a way to get capture it and display it back into Kodi with out doing anything 2 it? Is the byte arry still a image of just a bunch of number... That is the part I can't wrap my minD around yet . Sorry I know this is probably trivial​ to you. And I really and try to look things up about bytearry and I do see there is alot can be done with it... But most examples are using a image saved on a drive somewhere and with this it an actual video so that has me off a bit.

1. I'm not sure why you would want to write the image, writing the image would be taxing and not a fair assignment of the code you are writing.
2. It's all ones and zeros, semantics Tongue ... I'm not 100% sure the specifics of an image byte array, in general a byte array is a bunch of indexed bytes. Bytes in a array, I'd assume a image byte array means every pixel (image element) is addressable.

Stay away from any image saving, you don't want this... it would kill the performance of the machine running the code (ie drop the capture frame rate drastically). It would also thrash your storage device.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#35
I wasn't planing to write the image in the final code just as a check as I build up to a product.... All it all I found some more docs on this topic so now I just need to read a test to seenif I can get it to do anything lol.

And I may have missed read but I should be able to display the image from the buffer without saving it to the system... A simple one to one... But either way I still have a some more reading to do. To actually get the bytearry out of Kodi and checking the player in Kodi to see if it is playing... As I haven't had much luck with it yet I continue to get sytanx error where I am using the code wrong. Hopefully I will figure it out sooner then later.
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#36
Can anyone explain how the width and high relate to the rendercapture()

Can I specify a specific area on the screen for it to capture from?
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#37
Yes you can but you need to calculate it by yourself, since the bytearray is linear....
Reply
#38
Not trying to seem to needy but is there any doc I can look at to figure out how to calculate the locations

I went to here but it doesn't tell me much, or I if it does I don't understand it lol
https://codedocs.xyz/xbmc/xbmc/group__py...pture.html?

I may be totally wrong but when I search for this it keeps coming back to a Kodi thing so I am guessing someone made this module just for Kodi?
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#39
Oh, sorry, you can't specify capture area but you can specify resolution. You can only capture whole screen and then "take out" the area you need. And for that you need to calculate the area from linear bytearray into x/y.
Reply
#40
So, this is still related but I am working on something different.

my question is how do I get the a image from the video playing.
I am thinking this may work if I could get the image there.

PHP Code:
def test(path):
    
filename md5 "test.jpg"
    
targetfile os.path.join(addondatapathfilename)
    
count os.stat(path).st_size/2
    with open
(path,"rb") as f:
        return 
bytearray(f.read())
    
byte readimage(path)
    
img Image.open(io.BytesIO(byte))
    
img.save(targetfile

so would som how use:
PHP Code:
path xbmc.RenderCapture().capture() 

or would I need to use
PHP Code:
path xbmc.RenderCapture().getImage() 

my goal for now I just want to beable to take a picture of just the video that is playing. Once I can see what I am doing then I will try to build on it from there.
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#41
PHP Code:
w   =    50
    h 
=    50

    xbmc
.RenderCapture().capture(w,h)
    
img xbmc.RenderCapture().getImage()
    
fmt xbmc.RenderCapture().getImageFormat()
    
ar xbmc.RenderCapture().getAspectRatio() 
    
bytebytearray(img)  
    
xbmcgui.Dialog().ok("Test"str(fmt), str(ar))
    
newimg Image.frombuffer('RGBA', (wh), byte'raw''RGBA'01

I have this and give me the format and the aspect ratio. so assumeing it is getting this info from the bytearray then that would be this is working as far as captureing the image.

but now can someone point me in the direction of getting the image to a .png or .jpeg

when running this I get
PHP Code:
NOTEIGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            
Error Type: <type 'exceptions.ValueError'>
                                            
Error Contentsbuffer is not large enough
                                            Traceback 
(most recent call last):
                                              
File "H:\_demo\Kodi_18\portable_data\addons\script.crow\default.py"line 241in <module>
                                                
newimg Image.frombuffer('RGBA', (wh), byte'raw''RGBA'01)
                                              
File "H:\_demo\Kodi_18\addons\script.module.pil\lib\PIL\Image.py"line 2117in frombuffer
                                                core
.map_buffer(datasizedecoder_nameNone0args)
                                            
ValueErrorbuffer is not large enough 

How do I make the buffer larger?
I have readed and racked my brain for hours on this. I really am trying even if it doesn't seem like it.
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#42
I tried this:
PHP Code:
w   =  xbmc.RenderCapture().getWidth()
    
h   =  xbmc.RenderCapture().getHeight()
    
xbmc.RenderCapture().capture(w,h)
    
img xbmc.RenderCapture().getImage()
    
fmt xbmc.RenderCapture().getImageFormat()
    
ar xbmc.RenderCapture().getAspectRatio() 
    
# byte= bytearray(img)  
    
xbmcgui.Dialog().ok("Test"str(fmt), str(ar))
    
pi Image.frombuffer('RGBA', (hw), img'raw''RGBA'01)
    
pib pi.tobytes()
    
pi_fixed Image.frombytes('RGBA', (hw), pib'raw''BGRA'01)
    
filename ="test.jpg"
    
fn = os.path.join(ADDON_DATA_PATHfilename)
    
pi_fixed.save(fn) 
And Get this
PHP Code:
NOTEIGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            
Error Type: <type 'exceptions.SystemError'>
                                            
Error Contentstile cannot extend outside image
                                            Traceback 
(most recent call last):
                                              
File "H:\_demo\Kodi_18\portable_data\addons\script.crow\default.py"line 253in <module>
                                                
pib pi.tobytes()
                                              
File "H:\_demo\Kodi_18\addons\script.module.pil\lib\PIL\Image.py"line 678in tobytes
                                                e
.setimage(self.im)
                                            
SystemErrortile cannot extend outside image
                                            
-->End of Python script error report<-- 

Nobody know how to turn this into actually image?
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#43
I have read through the forum and see some people say the are only getting black images... Can anyone tell or point me to how to get a image of any kind from this .... Still can't find the right information to get this working.

Will really appreciate and advice this has me stumped
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#44
Sorry to spam thread but I found this thread

https://forum.kodi.tv/showthread.php?tid=183815

And I have done everything in this ... I can not get a image because the buffer is not large enough.

Any ideas to what is causing this?
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply
#45
Code:
size =(capture.getWidth(),capture.getHeight())
    mode="RGBA"
    img=Image.frombuffer(mode,size,capture.getImage(),'raw',mode,0,1)
    img.save("G:\\Kodi_17_RC4.old\\portable_data\\userdata\\addon_data\\script.test\\test.jpg")

Using this i now get a "image" that cant be opened but i also get this error

Code:
20:24:38.116 T:3860   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SystemError'>
                                            Error Contents: tile cannot extend outside image
                                            Traceback (most recent call last):
                                              File "G:\Kodi_17_RC4.old\portable_data\addons\script.crow\default.py", line 235, in <module>
                                                img.save("G:\\Kodi_17_RC4.old\\portable_data\\userdata\\addon_data\\script.test\\test.jpg")
                                              File "G:\Kodi_17_RC4.old\addons\script.module.pil\lib\PIL\Image.py", line 1675, in save
                                                save_handler(self, fp, filename)
                                              File "G:\Kodi_17_RC4.old\addons\script.module.pil\lib\PIL\JpegImagePlugin.py", line 708, in _save
                                                ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
                                              File "G:\Kodi_17_RC4.old\addons\script.module.pil\lib\PIL\ImageFile.py", line 483, in _save
                                                e.setimage(im.im, b)
                                            SystemError: tile cannot extend outside image
                                            -->End of Python script error report<--

Any Ideas to why i am getting this error or how to get the image view able even if it is black?
Shield TV | Windows 10 | Mariadb | Mii Box
Evolve Ecosystem Repo | TV Melodies | Madnox Holiday Mod
Reply

Logout Mark Read Team Forum Stats Members Help
RenderCapture need help0