#!/bin/sh
#用vcdimager將mpg轉檔成.bin 及.cue 兩檔
#cd /home
#vcdimager disk1.mpg
#燒錄
#cdrdao write --device 0,1,0 --driver generic-mmc --speed 24 videocd.cue
#cdrdao write --device 0,0,0 --driver generic-mmc --speed 12 videocd.cue
USAGE="$0 speed dat_file"
if [ $# -ne 2 ]; then
 echo "$USAGE"
 echo "Example:"
 echo "./$0 /mnt/vcd/disk01.dat"
 exit 1
fi

speed="$1"
img="$2"
if [ ! -f "$img" ]; then
  echo "Can NOT find $img"
  exit 1
fi
output_prefix="vcd_XXX"
output_cue="$output_prefix"."cue"
output_bin="$output_prefix"."bin"
if [ -f "$output_cue" ]; then
  rm -rf $output_cue
fi
if [ -f "$output_bin" ]; then
  rm -rf $output_bin
fi
echo "output_cue: $output_cue"
vcdimager -c $output_cue -b $output_bin "$img"
if [ $? -ne 0 ]; then
  echo "Failed to finish vcdimager... Program stop! "
  exit 1
fi
cdrdao write --device 0,0,0 --driver generic-mmc-raw --speed $speed --buffers 64 --eject --on-the-fly $output_cue

