How to reload an image file that changes its content in an effective way?
#1
Hi,
I created my first addon that provides a rudimentary picture-in-picture function:
https://github.com/mltobi/kodi-pip-addon

I tried to use setImage() function to reload an image file cyclically. This image file is always the same file and is updated by a ffmpeg process.
However that does not work because setImage() seems not to recognize that the content of the image has changed.

In order to get a kind of reload I use two overlapping image controls.
This is necessary in order to keep the image shown by the 2nd control when the 1st control is removed.
The removal is required to reload the same image file in order to show the new content.

Unfortunately, this leads sometimes to flickers during displaying the updated image.
And the frame rate is very limited due to time of adding and removing an image control.

Is there a more effective way to display and reload automatically an image file that changes its content and timestamp.

Here is the code part I use to add and remove the two overlapping image controls:
python:

# remove 2nd image control
if self.img2:
    self.winHdl.removeControl(self.imgHdl2)
    del self.imgHdl2
    self.img2 = False

# create 1st image control
self.imgHdl1 = xbmcgui.ControlImage(self.x, self.y, self.w, self.h, self.imagefile)
self.img1 = True

# add 1st control to windows handle
self.winHdl.addControl(self.imgHdl1)

# wait half frame rate
xbmc.sleep(500)

# create 2nd image control to overlap the 1st image control
self.imgHdl2 = xbmcgui.ControlImage(self.x, self.y, self.w, self.h, self.imagefile)
self.img2 = True

# add 2nd control to windows handle
self.winHdl.addControl(self.imgHdl2)

# remove 1st control
if self.img1:
    self.winHdl.removeControl(self.imgHdl1)
    del self.imgHdl1
    self.img1 = False

# wait half frame rate
xbmc.sleep(500)

Thanks
tobi
Reply
#2
Try set animation.

python:
self.imgHdl1.setAnimations([('visible', 'effect=fade end=100 time=300 delay=300',)])
Reply
#3
have you tried setImage() with caching set to false?
https://codedocs.xyz/xbmc/xbmc/group__py...116a784ac5
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#4
Thanks for your hints M89SE and ronie.

However I now use a different approach. I add only one image control and change the filename by adding a uuid in order to "force" the reload of the image.
I use setImage() with no caching. I hope this avoids that the different files are not added to the kodi databases...

Here is the new code snippet:
python:

        # if video fullscreen window ID
        if winId == self.winId and os.path.exists(self.imagefile):
            if not self.img:
                self.imgHdl = xbmcgui.ControlImage(self.x, self.y, self.w, self.h, self.imagefile)
                self.winHdl.addControl(self.imgHdl)
                self.img = True

            # add to latest captured image a unique id in order to force reload the image via setImage function
            olduuidfile = self.uuidfile
            self.uuidfile = self.imagefile.replace(".png", "%s.png" % str(uuid.uuid4()))
            shutil.copy(self.imagefile, self.uuidfile)

            # set new image file
            self.imgHdl.setImage(self.uuidfile, useCache = False)

            # remove already set image file if it exists
            if olduuidfile != None:
                if os.path.exists(olduuidfile):
                    os.remove(olduuidfile)
Reply

Logout Mark Read Team Forum Stats Members Help
How to reload an image file that changes its content in an effective way?0