# Displaying PNG/GIF dynamic on a temp file structure?

**URL:** <https://rpi-rgb-led-matrix.discourse.group/t/displaying-png-gif-dynamic-on-a-temp-file-structure/184>\
**Category:** Uncategorized\
**Created:** [March 30, 2021, 6:14pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/displaying-png-gif-dynamic-on-a-temp-file-structure/184 "2021-03-30T18:14:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayrankin](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jayrankin](https://rpi-rgb-led-matrix.discourse.group/u/jayrankin)\
**Post date:** [March 30, 2021, 6:14pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/displaying-png-gif-dynamic-on-a-temp-file-structure/184/1 "2021-03-30T18:14:55Z")

</div>

Hi All,  
Im really new with everything matrix/raspberry/python. I have got panels working and using imagine viewer and all the examples.  
What im trying to get working now is using the same logic as a program called Pimarquee2 that displays automatically on the PI4 second HDMI display.  
I have changed the code to point to led-image-viewer instead of the omxplayer.

Can anyone give some pointers on how to get this working?  
Or suggest another way with the working result? perhaps a way to copy whatever is displaying on the second HDMI port and display on the LCD’s?

thanks in advance!

here is the script i have been changing - credit to Loosernator built built the script on Github.

#!/usr/bin/python3

import os  
from subprocess import \*  
from time import \*  
import xml.etree.ElementTree as ET

## INTRO = “/home/pi/PieMarquee2/intro.mp4”

INTRO = “/home/pi/PieMarquee2/intro.png”

## for DPI screen

#VIEWER = “/opt/retropie/configs/all/PieMarquee2/omxiv-marquee /tmp/marquee.txt -f -b -d 4 -t 5 -T blend --duration 900 \> /dev/null 2\>&1 &”

## for Pi4 hdmi1

#VIEWER = “/opt/retropie/configs/all/PieMarquee2/omxiv-marquee /tmp/marquee.txt -f -b -d 7 -t 5 -T blend --duration 900 \> /dev/null 2\>&1 &”

# 

#Tesing line for imageviewer software  
VIEWER = “/opt/retropie/configs/all/PieMarquee2/led-image-viewer /tmp/marquee.txt --led-no-hardware-pulse --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=2 --led-gpio-mapping=adafruit-hat &”  
arcade = [‘arcade’, ‘fba’, ‘mame-advmame’, ‘mame-libretro’, ‘mame-mame4all’]

def run\_cmd(cmd):

# runs whatever in the cmd variable

```
p = Popen(cmd, shell=True, stdout=PIPE)
output = p.communicate()[0]
return output.decode()

```

def kill\_proc(name):  
ps\_grep = run\_cmd("ps -aux | grep " + name + “| grep -v ‘grep’”)  
if len(ps\_grep) \> 1:  
os.system("killall " + name)

def is\_running(pname):  
ps\_grep = run\_cmd(“ps -ef | grep " + pname + " | grep -v grep”)  
if len(ps\_grep) \> 1:  
return True  
else:  
return False

def get\_publisher(romname):  
filename = romname+".zip"  
publisher = “”  
for item in root:  
if filename in item.findtext(‘path’):  
publisher = item.findtext(‘publisher’)  
break  
if publisher == “”:  
return “”  
words = publisher.split()  
return words[0].lower()

if os.path.isfile(INTRO) == True:  
## for DPI screen  
#run\_cmd("omxplayer --display 4 " + INTRO)  
## for Pi4 hdmi1  
run\_cmd("omxplayer --display 7 " + INTRO)  
## for LED  
run\_cmd("led-image-viewer --led-no-hardware-pulse --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=2 --led-gpio-mapping=adafruit-hat " + INTRO )

doc = ET.parse("/opt/retropie/configs/all/PieMarquee2/gamelist\_short.xml")  
root = doc.getroot()

if os.path.isfile("/home/pi/PieMarquee2/marquee/system/maintitle.gif") == True:  
## for DPI screen  
#os.system(“omxplayer --loop --no-osd --display 4 /home/pi/PieMarquee2/marquee/system/maintitle.mp4 &”)  
## for Pi4 hdmi1  
os.system(“omxplayer --loop --no-osd --display 7 /home/pi/PieMarquee2/marquee/system/maintitle.mp4 &”)  
## for LED added into script  
os.system(“led-image-viewer -C /home/pi/PieMarquee2/marquee/system/maintitle.png --led-no-hardware-pulse --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=2 --led-gpio-mapping=adafruit-hat &”)  
else:  
os.system(“echo ‘/home/pi/PieMarquee2/marquee/system/maintitle.png’ \> /tmp/marquee.txt”)  
os.system(VIEWER)

cur\_imgname = “system/maintitle”

while True:  
sleep\_interval = 1  
ingame = “”  
romname = “”  
sysname = “”  
pubpath = “”  
instpath = “”  
imgpath = “”  
ps\_grep = run\_cmd(“ps -aux | grep emulators | grep -v ‘grep’”)  
if len(ps\_grep) \> 1: # Ingame  
ingame="_"  
words = ps\_grep.split()  
if ‘advmame’ in ps\_grep:  
sysname = “arcade”  
romname = words[-1]  
else:  
pid = words[1]  
if os.path.isfile("/proc/"+pid+"/cmdline") == False:  
continue  
path = run\_cmd(“strings -n 1 /proc/”+pid+"/cmdline | grep roms")  
path = path.replace(’/home/pi/RetroPie/roms/’,’’)  
if len(path.replace(’"’,’’).split("/")) \< 2:  
continue  
sysname = path.replace(’"’,’’).split("/")[0]  
if sysname in arcade:  
sysname = “arcade”  
romname = path.replace(’"’,’’).split("/")[-1].rsplit(’.’, 1)[0]  
elif is\_running(“gif”) == True: # Video screensaver (OMXplayer)  
ps\_grep = run\_cmd(“ps -aux | grep mp4 | grep -v ‘grep’”)  
if ‘RetroPie’ in ps\_grep:  
words = ps\_grep.split()  
pid = words[1]  
if os.path.isfile("/proc/"+pid+"/cmdline") == False:  
continue  
path = run\_cmd(“strings -n 1 /proc/”+pid+"/cmdline | grep roms")  
if len(path.replace(’"’,’’).split("/")) \< 2:  
continue  
sysname = path.replace(’"’,’’).split("/")[-3]  
if sysname in arcade:  
sysname = “arcade”  
romname = path.replace(’"’,’’).split("/")[-1].rsplit(’.’, 1)[0]  
elif os.path.isfile("/tmp/PieMarquee.log") == True: # Extended ES  
f = open(’/tmp/PieMarquee.log’, ‘r’)  
line = f.readline()  
f.close()  
words = line.split()  
if len(words) \> 1 and words[0] == “Game:”: # In the gamelist-\> Game: /home/pi/…/_.zip  
path = line.replace(‘Game: ‘,’’)  
path = path.replace(’/home/pi/RetroPie/roms/’,’’)  
sysname = path.replace(’"’,’’).split("/")[0]  
if sysname in arcade:  
sysname = “arcade”  
romname = path.replace(’"’,’’).split("/")[-1].rsplit(’.’, 1)[0]  
sleep\_interval = 0.1 # for quick view  
elif len(words) == 1:  
sysname = “system”  
if words[0] == “SystemView”:  
romname = “maintitle”  
else:  
romname = words[0]  
else:  
sysname = “system”  
romname = “maintitle”

```
if os.path.isfile("/home/pi/PieMarquee2/marquee/" + sysname + "/" + romname + ".png") == True:
    imgname = sysname + "/" + romname
    if ingame == "*":
        publisher = get_publisher(romname)
        if os.path.isfile("/home/pi/PieMarquee2/marquee/publisher/" + publisher + ".png") == True:
            pubpath = "/home/pi/PieMarquee2/marquee/publisher/" + publisher + ".png"
        if os.path.isfile("/home/pi/PieMarquee2/marquee/instruction/" + romname + ".png") == True:
            instpath = "/home/pi/PieMarquee2/marquee/instruction/" + romname + ".png"
elif os.path.isfile("/home/pi/PieMarquee2/marquee/system/" + sysname + ".png") == True:
    imgname = "system/" + sysname
else:
    imgname = "system/maintitle"

if imgname+ingame != cur_imgname: # change marquee images
    kill_proc("omxplayer.bin")
    if imgname == "system/maintitle" and os.path.isfile("/home/pi/PieMarquee2/marquee/system/maintitle.mp4") == True:
        ## for DPI screen
        #os.system("omxplayer --loop --no-osd --display 4 /home/pi/PieMarquee2/marquee/system/maintitle.mp4 &")
        ## for Pi4 hdmi1
        ##kill_proc("omxiv-marquee")
        ##os.system("omxplayer --loop --no-osd --display 7 /home/pi/PieMarquee2/marquee/system/maintitle.mp4 &")
         ## for LED added into script
        kill_proc("led-image-viewer")
        os.system("led-image-viewer -C /home/pi/PieMarquee2/marquee/system/maintitle.gif --led-no-hardware-pulse --led-rows=32 --led-cols=64 --led-chain=2 --led-slowdown-gpio=2 --led-gpio-mapping=adafruit-hat &")
        cur_imgname = imgname+ingame
    else:
        '''
        f = open("/tmp/marquee.txt", "w")
        if pubpath != "":
            f.write(pubpath+"\n")
        f.write("/home/pi/PieMarquee2/marquee/" + imgname + ".png")
        if instpath != "":
            f.write("\n"+instpath)
        f.close()
        '''
        if os.path.isfile("/home/pi/PieMarquee2/marquee/custom/" + romname + ".txt") == True and ingame == "*":
            os.system("cp /home/pi/PieMarquee2/marquee/custom/" + romname + ".txt /tmp/marquee.txt")
        else:
            imgpath = "/home/pi/PieMarquee2/marquee/" + imgname + ".png"
            if ingame == "*":
                if pubpath != "":
                    imgpath = pubpath+"\n"+imgpath
                if instpath != "":
                    imgpath = imgpath+"\n"+instpath
            os.system('echo "' + imgpath + '" > /tmp/marquee.txt')
        sleep(0.2) 
        if is_running("led-image-viewer") == False: # if omxiv failed, execute again
            os.system("clear > /dev/tty1")
            os.system('echo "' + imgpath + '" > /tmp/marquee.txt')
            os.system(VIEWER)
        cur_imgname = imgname+ingame

sleep(sleep_interval)
```
