Last active
February 18, 2017 02:57
-
-
Save withmorten/5784de8cfba1b2b4dd0c15efc9d1fad1 to your computer and use it in GitHub Desktop.
cod4ff extract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const WAV_NEEDLE = ".wav"; | |
const WAV_PACKID = "feffffff"; | |
const DEFAULTPATH = "sound"; | |
$ffdump = file_get_contents($argv[1]); | |
$lastpos = 0; | |
$wav_pathid = hex2bin("FFFFFF"); | |
$wavs = array(); | |
$c = 0; | |
while(($lastpos = strpos($ffdump, WAV_NEEDLE, $lastpos)) !== FALSE) { | |
$wav_start = strrpos($ffdump, $wav_pathid, -(strlen($ffdump) - ($lastpos - 1))); | |
$wav_id = bin2hex(substr($ffdump, $wav_start-1, 4)); | |
$wav_name = substr($ffdump, $wav_start+3, ($lastpos+4)-($wav_start+3)); | |
if($wav_id == WAV_PACKID) { | |
$wav_header = substr($ffdump, $wav_start-37, 36); | |
$wav_length = hexdec(bin2hex(strrev(substr($wav_header, 8, 4)))); | |
$wav_sample = hexdec(bin2hex(strrev(substr($wav_header, 12, 4)))); | |
$wav_chanel = hexdec(bin2hex(strrev(substr($wav_header, 20, 4)))); | |
$wavs[$c] = array("name" => $wav_name, "start" => $lastpos+5, "length" => $wav_length, "sample" => $wav_sample, "channels" => $wav_chanel); | |
$c++; | |
} | |
$lastpos = $lastpos + strlen(WAV_NEEDLE); | |
} | |
if(!file_exists(DEFAULTPATH)) { | |
mkdir(DEFAULTPATH); | |
} | |
foreach($wavs as $c => $wav) { | |
$explodepath = explode("/", $wav["name"]); | |
$pathsize = count($explodepath); | |
$oldpath = DEFAULTPATH."/"; | |
for($i = 1; $i <= $pathsize; $i++) { | |
$fullpath = $oldpath.$explodepath[$i-1]; | |
if($i != $pathsize) { | |
if(!file_exists($fullpath)) { | |
mkdir($fullpath); | |
} | |
$oldpath = $fullpath."/"; | |
} else { | |
file_put_contents($fullpath, substr($ffdump, $wav["start"], $wav["length"])); | |
$ffmpeg = "ffmpeg -y -f s16le -ac ".$wav["channels"]." -ar ".$wav["sample"]." -i $fullpath ".substr($fullpath, 0, -4)."_PCM.wav\n"; | |
echo $ffmpeg; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works only with unzipped dumps. Use like this:
Works in conjunction with the following script that parses the ffmpeg commands for dupes:
https://gist.github.com/withmorten/06f9d65ec138808edeeb956501d9ec0a