Page 1 of 1

CUE to CHD Batch Conversion on Windows

Posted: Wed Jan 06, 2021 2:27 pm
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"
)

Re: CUE to CHD Batch Conversion on Windows

Posted: Thu Jan 07, 2021 2:31 pm
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.

Re: CUE to CHD Batch Conversion on Windows

Posted: Sat May 01, 2021 5:01 am
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

Re: CUE to CHD Batch Conversion on Windows

Posted: Sun Jul 03, 2022 7:34 pm
by Zarkov
Anyone have a version of this for Lunux (Ubuntu)?
I have found this :
for %i in (*.cue) do chdman createcd -i "%i" -o "%~ni.chd"

But it fails to work. The error I get is
line 1: syntax error near unexpected token `('

If I remove the () I get:
line 3: syntax error: unexpected end of file

All I want it to do is run the command:
chdman createcd -i "game name.cue" -o "game name.chd"
For every .cue file it finds in the directory. No creation of new directories etc.

I found this :

#!/bin/bash

# Grab .cue file
for f in ./**/*.cue
do
name=${f%.cue} # Remove '.cue' from file name
chdman createcd -i "$name.cue" -o "$name.chd" --force
done

If I don't want it to go through sub directories and only do the files inside the directory where I run the .sh file from, what part of the code would I remove? I'm thinking its the "in ./**" so maybe "for f in ./*.cue" ?

I ran this code in a script and I get this error:
Error parsing input file (./**/*.cue: file not found)

I found out that the error happened because there are no directories inside the directory where I ran the script from. I made a directory and added a game to it and then ran it and it converted the game in the directory I made.

I'll try and run it one directory below the directory containing all my games and hopefully it will process all of them.

*update
I learned that if I put the script in a folder, it only goes one folder above to convert games. So If it was pretty simple to control what directories it will target. Since I had most of the games separated by multiple levels of directories.

I'm curious if I run it again, after the chd's are already there, if it will do it all over again and replace the files or just convert new files that do not yet have chd's.