#!/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 recorder_id"
if [ $# -ne 3 ]; then
 echo "$USAGE"
 echo "Example:"
 echo "$0 48 /mnt/vcd/disk01.dat 0"
 echo "It will burn the disk01.dat to VCD format in CD recorder ID 0 with speed 48."
 exit 1
fi

speed="$1"
img="$2"
recorder_id="$3"
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
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,$recorder_id,0 --driver generic-mmc-raw --speed $speed --buffers 64 --eject --on-the-fly $output_cue
if [ $? -eq 0 ]; then
  echo "Successfully make it! "
  echo "Remove the image file..."
  rm -f $output_bin $output_cue
  exit 0
fi

