[LINUX] Automatically Convert Backdrop Images to BMP
#1
On the Acer Revo and other similar devices, using .bmp images for your backdrops can really improve performance, especially in skins like Aeon.

I wrote a little script to automatically do this and just thought I would share it since I didn't find much when I searched for something like this.

You can put this in a file in /etc/cron.hourly , just don't forget to chmod +x the file after you create it. Oh, and don't use a file name with a "." in it for your script or run-parts (cron) won't pick it up.

Code:
#!/bin/bash

DIRS[1]=/home/xbmc/.xbmc/userdata/Thumbnails/Music/Fanart
DIRS[2]=/home/xbmc/.xbmc/userdata/Thumbnails/Video/Fanart
DIRS[3]=/home/xbmc/.xbmc/media/backdrops/pictures
DIRS[4]=/home/xbmc/.xbmc/media/backdrops/settings

for DIR in ${DIRS[@]}; do
  (IFS=$'\n'
  for i in `find $DIR -type f | fgrep -e bmp -e BMP -v`; do
    FILENAME=`basename $i`
    FILENAME_NOEXT=`echo $FILENAME | cut -d'.' -f1`
    convert $i $DIR/$FILENAME_NOEXT.bmp
    rm -f $i
  done
  )
done

This requires Imagemagick to do the conversion, so make sure you have that installed first.
Reply
#2
nevermind, sorry
Reply
#3
Better yet, use dds files.
Reply
#4
Code:
#!/bin/bash

DIRS[1]=/home/xbmc/.xbmc/userdata/Thumbnails/Music/Fanart
DIRS[2]=/home/xbmc/.xbmc/userdata/Thumbnails/Video/Fanart

for DIR in ${DIRS[@]}; do
        for f in `find $DIR -type f | grep -e ".bmp" -i -v`; do
                FILENAME=${f##*/};
                BASE=${FILENAME%%.*}
                NEW_FILE=$DIR/$BASE.bmp;
                if [ ! -e $NEW_FILE ]; then
                        CMD="convert $f $NEW_FILE";
                        eval $CMD;
                        rm -rf $f;
                fi
        done
done

Mine, if the file already exists, it doesn't do anything (no use wasting the CPU every hour)
Reply
#5
My script won't do anything if the file has already been converted either because the converted files have been renamed with .bmp extension. The script only finds and acts on non-bmp files.
Reply
#6
cp_clegg Wrote:My script won't do anything if the file has already been converted either because the converted files have been renamed with .bmp extension. The script only finds and acts on non-bmp files.

Duh... good call. Mine does too.
Reply
#7
For those that are wondering "well what sort of speed up":

Here is a before:
Code:
18:34:56 T:2938108784 M:765120512   DEBUG: DoWork - took 505 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn
18:35:29 T:2844461936 M:782389248   DEBUG: DoWork - took 713 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn
18:35:44 T:2854951792 M:781484032   DEBUG: DoWork - took 496 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn
18:35:58 T:2938108784 M:777392128   DEBUG: DoWork - took 520 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn
18:36:12 T:2844461936 M:777494528   DEBUG: DoWork - took 492 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn

and After:
Code:
18:36:40 T:2865998704 M:781426688   DEBUG: DoWork - took 105 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn
18:36:58 T:2865998704 M:781414400   DEBUG: DoWork - took 106 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn
18:38:56 T:2854951792 M:779677696   DEBUG: DoWork - took 110 ms to load special://masterprofile/Thumbnails/Video/Fanart/3535cd43.tbn

for one show's fanart.

Here's my latest script:
Code:
#!/bin/bash

DIRS[1]=/home/xbmc/.xbmc/userdata/Thumbnails
temp="/tmp/0.$RANDOM.bmp"
for DIR in ${DIRS[@]}; do
    for f in `find $DIR -type f -name *.tbn`; do
        file $f | grep "PC bitmap" > /dev/null
        if [ $? -ne 0 ];then
            echo "converting $f";
            CMD="convert \"$f\" \"$temp\""
            CMD2="mv \"$temp\" \"$f\""
            eval $CMD;
            eval $CMD2;
        else
            echo "$f already converted."
        fi
    done
done

I kept the tbn extension because some where I read that's where it looks first.
Reply

Logout Mark Read Team Forum Stats Members Help
[LINUX] Automatically Convert Backdrop Images to BMP0