Solved Chapter Selector Window
I have been moving my old DVD collection to mpeg 4 files for some time now (300+ DVD's), and during the encoding process I have been embedding the chapter names in the encoded files (mostly grabbed from chapterdb.org) using the "--markers" option & a csv file during the Handbrake encoding.
I began looking for a way to display all of the chapters inside of xbmc/kodi (complete with a short looping video clip, or a screenshot from each chapter), and this add-on looked like a great fit for what I needed.
The only problem I faced with this add-on was creating all of the screenshots, and the xml file for this add-on to display all of the data I wanted to see.
I wrote a quick shell script to create a sub-directory "chapters" where the movie exists, and place all of the jpg screenshots inside of that directory.
This script will also create the xml file needed to display this information inside of kodi.
A couple external programs are needed to run this: mediainfo & ffmpeg

I'm sure this could be improved somewhat, but I really wanted to make this a simple command line script that can be easily automated. Possibly even to the point of being integrated into this add-on in the future at some point.
Any, and all feedback is welcome. Please see below for the script, and how it works.
Enjoy!

Code:
./chapterimages.sh /path/to/moviefile.mkv
This will create:
/path/to/moviefile.chapters.xml
/path/to/chapters/
/path/to/chapters/moviefile-001.jpg
/path/to/chapters/moviefile-002.jpg
/path/to/chapters/moviefile-003.jpg
etc...

Code:
#!/bin/bash
#chapterimages.sh
#created by The_Dave; 4.22.15

### Choose the same of the subdirectory you want all of the screenshot images to be placed in
THUMBS="chapters"

### END EDITABLE SECTION
### The script below will create the xml file & needed chapter images for each video defined after the script call
### example:  user@shell> chapterimages.sh video_file.mkv

FILE=$1
n=${FILE,,}
#directory the file exists in
nn=$(dirname $n)
#just the filename
m=$(basename "$n")
#the "base" file name with NO extension
mkf=${m%%.*}

CHAPIMGS=$nn/$THUMBS
XMLFILE=$mkf.chapter.xml
DESTFILE=$nn/$XMLFILE

### Perform checks to see if the files / directories already exist
if [ ! -d "$CHAPIMGS" ]; then
  echo "The directory $CHAPIMGS was NOT found; It will be created for you";
  mkdir $CHAPIMGS
fi
if [ -e "$DESTFILE" ]; then
  echo "The chapter XML file $DESTFILE already exists";
  echo "Please delete this file before running this command again; exiting"
  exit
fi

echo "Beginning work on the chapters images & xml file for the video: $mkf"

#determine the image caputure size from the video resoltion
SIZE=`mediainfo "--Inform=Video;%Width%x%Height%" $FILE`
#get the list of chapters from the video file
CHAPSTR=`mediainfo --Output=CSV $FILE |egrep "^[0-9]{2}:[0-9]{2}:\.*"`
IFS=$'\n'
CHAPARR=( $CHAPSTR )
N=1

XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><chapters>'

for i in "${CHAPARR[@]}";do
  #cheat to create leading zero for image file names;supports up to 999 chapters
  nm=00$N
  num="${nm: -3}";
  echo "Chapter: $num -Image: $mkf-$num.jpg -Time,Name: $i";
  ts="$( cut -d ',' -f 1 <<< "$i" )";
  chapname="$( cut -d ',' -f 2- <<< "$i" )";
  #change quote characters to xml friendly
  chapname=${chapname//\"/&quot;}
  chapname=${chapname//\'/'}
  XML="$XML<chapter mark=\"$ts\" title=\"$chapname\" title2=\"\" thumb=\"chapters/$mkf-$num.jpg\" />"
  if [ -e "$CHAPIMGS/$mkf-$num.jpg" ]; then
    echo "The chapter image file $mkf-$num.jpg already exists...";
    echo "Please delete this image file before running this command again; exiting"
    exit;
  else
    ###Tried making 3 images every 3 seconds after the timestamp, but was not much better...
    #ffmpeg -ss $ts -i $FILE -vframes 3 -t 3 -s $SIZE $CHAPIMGS/$mkf-$num-%03d.jpg >/dev/null 2>&1
    ffmpeg -ss $ts -i $FILE -vframes 1 -t 1 -s $SIZE $CHAPIMGS/$mkf-$num.jpg >/dev/null 2>&1
  fi
  ((N++))
done

XML="$XML</chapters>"

#echo $XML
### Output the $XML to a new file
echo "$XML" > "$DESTFILE"
Reply


Messages In This Thread
Chapter Selector Window - by vidarak - 2013-04-24, 04:39
RE: Chapter Selector Window - by rd1979 - 2013-04-24, 05:21
RE: Chapter Selector Window - by Elky - 2013-04-24, 12:40
RE: Chapter Selector Window - by jpsdr - 2013-04-24, 13:25
RE: Chapter Selector Window - by vdubeau - 2013-04-28, 13:47
RE: Chapter Selector Window - by mika91 - 2013-05-07, 10:46
RE: Chapter Selector Window - by Ned Scott - 2013-05-07, 11:31
RE: Chapter Selector Window - by mad-max - 2013-06-03, 21:44
RE: Chapter Selector Window - by vidarak - 2013-07-04, 17:01
RE: Chapter Selector Window - by rd1979 - 2013-07-06, 09:18
RE: Chapter Selector Window - by capfuturo - 2013-07-27, 00:59
RE: Chapter Selector Window - by vidarak - 2013-08-23, 02:12
RE: Chapter Selector Window - by Memphiz - 2013-08-23, 15:48
RE: Chapter Selector Window - by lukemb - 2013-09-16, 01:51
RE: Chapter Selector Window - by lukemb - 2013-09-20, 01:29
RE: Chapter Selector Window - by lukemb - 2013-09-30, 04:58
RE: Chapter Selector Window - by vidarak - 2013-11-09, 04:26
RE: Chapter Selector Window - by DiMag - 2013-11-09, 10:57
RE: Chapter Selector Window - by crawfish - 2013-11-23, 21:53
RE: Chapter Selector Window - by JohanBoskamp - 2014-01-08, 20:34
RE: Chapter Selector Window - by vrm42 - 2013-11-25, 10:09
RE: Chapter Selector Window - by DWELLERZA - 2013-12-27, 11:03
RE: Chapter Selector Window - by ezechiel1917 - 2013-12-28, 16:45
RE: Chapter Selector Window - by MasterPhW - 2014-01-08, 00:54
RE: Chapter Selector Window - by da-anda - 2014-01-08, 09:55
RE: Chapter Selector Window - by Ned Scott - 2014-01-08, 14:44
RE: Chapter Selector Window - by Eisi2005 - 2014-01-08, 11:29
RE: Chapter Selector Window - by jjd-uk - 2014-01-08, 15:17
RE: Chapter Selector Window - by MassIV - 2014-01-08, 21:03
RE: Chapter Selector Window - by vidarak - 2014-01-31, 21:33
RE: Chapter Selector Window - by KWSRStorm - 2014-03-15, 19:15
RE: Chapter Selector Window - by vidarak - 2014-04-13, 21:29
RE: Chapter Selector Window - by nickr - 2014-04-13, 22:55
RE: Chapter Selector Window - by mika91 - 2014-04-16, 18:03
RE: Chapter Selector Window - by Ned Scott - 2014-04-17, 07:34
RE: Chapter Selector Window - by mika91 - 2014-04-17, 10:31
RE: Chapter Selector Window - by Ace - 2014-04-22, 17:44
RE: Chapter Selector Window - by WantedThing - 2014-04-19, 12:56
RE: Chapter Selector Window - by mika91 - 2014-04-22, 11:25
Re: Chapter Selector Window - by nickr - 2014-04-19, 20:47
RE: Chapter Selector Window - by mika91 - 2014-04-22, 17:06
RE: Chapter Selector Window - by vidarak - 2014-04-23, 21:30
RE: Chapter Selector Window - by jcmccorm - 2014-05-01, 17:01
RE: Chapter Selector Window - by vidarak - 2014-05-27, 10:16
RE: Chapter Selector Window - by vidarak - 2014-06-18, 12:29
RE: Chapter Selector Window - by HamDog - 2014-06-24, 16:31
RE: Chapter Selector Window - by shess757 - 2014-07-05, 01:50
RE: Chapter Selector Window - by Ned Scott - 2014-07-05, 04:23
RE: Chapter Selector Window - by shess757 - 2014-07-05, 13:21
RE: Chapter Selector Window - by vidarak - 2014-08-12, 21:07
RE: Chapter Selector Window - by vidarak - 2014-08-16, 23:39
RE: Chapter Selector Window - by Bytefire - 2014-10-03, 12:05
RE: Chapter Selector Window - by vidarak - 2014-10-24, 00:17
RE: Chapter Selector Window - by Ned Scott - 2014-10-24, 04:27
RE: Chapter Selector Window - by menakite - 2014-12-02, 03:52
RE: Chapter Selector Window - by 999unreal - 2014-12-07, 14:41
RE: Chapter Selector Window - by nickr - 2014-12-08, 01:50
RE: Chapter Selector Window - by mad-max - 2014-12-07, 22:20
RE: Chapter Selector Window - by 999unreal - 2014-12-09, 20:17
RE: Chapter Selector Window - by mad-max - 2014-12-09, 22:13
RE: Chapter Selector Window - by nickr - 2014-12-09, 22:33
RE: Chapter Selector Window - by mad-max - 2014-12-10, 12:44
RE: Chapter Selector Window - by rd1979 - 2014-12-10, 17:15
RE: Chapter Selector Window - by mad-max - 2014-12-10, 18:08
RE: Chapter Selector Window - by vidarak - 2014-12-10, 18:20
RE: Chapter Selector Window - by vidarak - 2014-12-20, 05:13
RE: Chapter Selector Window - by 999unreal - 2014-12-21, 09:36
RE: Chapter Selector Window - by 999unreal - 2015-01-10, 16:14
RE: Chapter Selector Window - by vidarak - 2015-01-17, 17:19
RE: Chapter Selector Window - by 999unreal - 2015-02-04, 06:13
RE: Chapter Selector Window - by ImpreZa - 2015-01-12, 21:53
RE: Chapter Selector Window - by Ned Scott - 2015-01-13, 09:15
RE: Chapter Selector Window - by nickr - 2015-01-13, 10:30
RE: Chapter Selector Window - by 999unreal - 2015-01-13, 12:13
RE: Chapter Selector Window - by vrm42 - 2015-01-13, 21:54
RE: Chapter Selector Window - by rd1979 - 2015-01-14, 16:01
RE: Chapter Selector Window - by 999unreal - 2015-01-15, 12:35
RE: Chapter Selector Window - by nickr - 2015-01-14, 19:55
RE: Chapter Selector Window - by rd1979 - 2015-01-14, 21:45
RE: Chapter Selector Window - by nickr - 2015-01-14, 23:03
RE: Chapter Selector Window - by rd1979 - 2015-01-15, 09:05
RE: Chapter Selector Window - by nickr - 2015-01-15, 10:20
RE: Chapter Selector Window - by rd1979 - 2015-01-15, 11:20
RE: Chapter Selector Window - by nickr - 2015-01-15, 11:57
RE: Chapter Selector Window - by rd1979 - 2015-01-15, 13:15
RE: Chapter Selector Window - by vidarak - 2015-02-16, 23:03
RE: Chapter Selector Window - by 999unreal - 2015-02-17, 14:49
RE: Chapter Selector Window - by vidarak - 2015-02-20, 14:23
RE: Chapter Selector Window - by Ace - 2015-03-02, 18:19
RE: Chapter Selector Window - by nickr - 2015-03-02, 22:38
RE: Chapter Selector Window - by Ace - 2015-03-02, 23:15
RE: Chapter Selector Window - by rd1979 - 2015-03-03, 05:57
RE: Chapter Selector Window - by nickr - 2015-03-03, 02:25
RE: Chapter Selector Window - by Eisi2005 - 2015-03-12, 15:52
RE: Chapter Selector Window - by jjd-uk - 2015-03-12, 16:01
RE: Chapter Selector Window - by Ace - 2015-03-12, 16:17
RE: Chapter Selector Window - by jjd-uk - 2015-03-12, 17:23
RE: Chapter Selector Window - by Eisi2005 - 2015-03-12, 16:25
RE: Chapter Selector Window - by Eisi2005 - 2015-03-12, 16:35
RE: Chapter Selector Window - by da-anda - 2015-03-12, 16:53
RE: Chapter Selector Window - by Eisi2005 - 2015-03-12, 17:02
RE: Chapter Selector Window - by Ace - 2015-03-12, 18:09
RE: Chapter Selector Window - by jjd-uk - 2015-03-12, 18:14
RE: Chapter Selector Window - by Ace - 2015-03-12, 18:24
RE: Chapter Selector Window - by jjd-uk - 2015-03-12, 18:33
RE: Chapter Selector Window - by vidarak - 2015-03-22, 01:55
RE: Chapter Selector Window - by Ace - 2015-03-22, 12:29
RE: Chapter Selector Window - by The_Dave - 2015-04-22, 19:33
RE: Chapter Selector Window - by magao - 2015-06-09, 02:46
RE: Chapter Selector Window - by Ned Scott - 2015-06-09, 03:43
RE: Chapter Selector Window - by ZwartePiet - 2015-12-30, 15:12
RE: Chapter Selector Window - by ezechiel1917 - 2015-12-30, 18:19
RE: Chapter Selector Window - by ZwartePiet - 2015-12-31, 06:41
RE: Chapter Selector Window - by ezechiel1917 - 2015-12-31, 15:00
Logout Mark Read Team Forum Stats Members Help
Chapter Selector Window3