CUE to CHD Batch Conversion (Windows)

If you have just joined the MiSTer community and are seeking help then post here.
Sumolx
Posts: 15
Joined: Sun Jun 07, 2020 1:50 am
Been thanked: 5 times

CUE to CHD Batch Conversion (Windows)

Unread post by Sumolx »

Perhaps people will find this script useful since the recent addition of the CHD image format is now supported. I created this script to perform the conversion from CUE/BIN to CHD in an automated fashion for the MegaCD and TG16 and figured I would share it...

Required Tools:
Mame

Instructions:
1. Create file called cue2chd.bat
2. Paste the code block below into the file cue2chd.bat
3. Update "chdman" variable to point to the file called "chdman.exe" (mame installation directory).
4. cue2chd.bat requires a folder called "cue" with all your images located within (or override src_path to where you store your images).
5. Executing cue2chd.bat will create a output path called "chd" to store the converted images within it.
6. Good Luck!!!

Code: Select all

@ECHO off

ECHO "##########################################################################"
ECHO "## Simple utility for batch conversions of CUE to CHD Images.           ##"
ECHO "##                                                                      ##"
ECHO "## Requires: Mame (http://mamedev.org)                                  ##"
ECHO "##                                                                      ##"
ECHO "## Directory Structure:                                                 ##"
ECHO "##                      /cue2chd.bat       <-- This file                ##"
ECHO "##                      /cue/              <-- Source Directory         ##"
ECHO "##                      /cue/file.cue                                   ##"
ECHO "##                      /cue/file.bin                                   ##"
ECHO "##                      /chd/              <-- Target Directory         ##"
ECHO "##                      /chd/file.chd                                   ##"
ECHO "##                                                                      ##"
ECHO "## This batch file is Public Domain do as you will.                     ##"
ECHO "##########################################################################"
ECHO 

REM Variables

SET chdman="C:\PATH_TO_MAME_EXECUTABLES\chdman.exe"
SET src_path="%CD%\cue"
SET dst_path="%CD%\chd"

REM Execution

IF NOT EXIST %dst_path% (
    MKDIR %dst_path%
)

FOR /R "%src_path%\" %%i IN ("*.cue") do (
    ECHO "%%i"
    MKDIR "%dst_path%\%%~ni"
    %chdman% createcd -i "%%i" -o "%dst_path%\%%~ni\%%~ni.chd"
)
KremlingKuthroat19
Posts: 104
Joined: Sat Aug 22, 2020 3:08 am
Has thanked: 11 times
Been thanked: 9 times

Re: CUE to CHD Batch Conversion (Windows)

Unread post by KremlingKuthroat19 »

Thanks for the post @Sumolx. I remember being skeptical of CHD before I used it in Retroarch, but the amount of data saved is extraordinary (30-45%) per disc. I've just saved over 50 GBs of data on my MiSTer and that's only for converting my Sega CD and TurboGrafx-CD library. This compression method will be huge once the PS1 core launches, and for using discs for the ao486 core.

There's a really great tutorial that helped me figure out how to use CHD too: https://www.youtube.com/watch?v=nAEoTXyz9Nk. He gives you a link on where to download the latest CHD tool (CHD v5), and all you'll need to do is drop your bins and cue files in this folder and hit the Bin to Cue command prompt. You can also reconvert the CHD to Bin/Cue using the other command prompt, but a caveat is that multiple bin games will convert to a single bin and therefore break the game.

CHD support is a big deal since it's the most commonly used compression tool that I'm aware of for early CD-based consoles (4th-5th gen). The MAME team created the tool and it's supported in all the CD-based cores in RetroArch.

Is it possible to get a wiki entry up for CHD support on the MiSTer github that directs people on how to download and use CHD, because I was completely lost until I found this video tutorial.
Sumolx
Posts: 15
Joined: Sun Jun 07, 2020 1:50 am
Been thanked: 5 times

Re: CUE to CHD Batch Conversion (Windows)

Unread post by Sumolx »

For those running into problems with chdman accepting very long files names. If you install Windows Linux Subsystem or use Linux... I've create this bash script which performs the same functionality of batch file conversions. However, this makes the assumption you already installed mame-tools via APT.

Code: Select all

#!/bin/bash

echo "##########################################################################"
echo "## Simple utility for batch conversions of CUE to CHD Images.           ##"
echo "##                                                                      ##"
echo "## Requires: chdman                                                     ##"
echo "##           sudo apt install mame-tools                                ##"
echo "##                                                                      ##"
echo "## Directory Structure:                                                 ##"
echo "##                      /cue2chd.sh        <-- This file                ##"
echo "##                      /cue/              <-- Source Directory         ##"
echo "##                      /cue/file.cue                                   ##"
echo "##                      /cue/file.bin                                   ##"
echo "##                      /chd/              <-- Target Directory         ##"
echo "##                      /chd/file.chd                                   ##"
echo "##                                                                      ##"
echo "## This batch file is Public Domain do as you will.                     ##"
echo "##########################################################################"
echo 

# Variables

src_path=$(pwd)/cue
dst_path=$(pwd)/chd

# Execution

find ${src_path}/ -type f -iname '*.cue' -print0 |
while IFS= read -r -d '' file;
do
    printf "%s\n" "$file"
    name=$(basename -- "$file")

    mkdir -p "$dst_path/${name%.*}"
    chdman createcd -i "$file" -o "$dst_path/${name%.*}/${name%.*}.chd"
done
Post Reply