Skip to content

Instantly share code, notes, and snippets.

@rsky
Created June 29, 2010 17:35
Show Gist options
  • Save rsky/457525 to your computer and use it in GitHub Desktop.
Save rsky/457525 to your computer and use it in GitHub Desktop.
DVファイルのアスペクト比を4:3から16:9に書き換える
<?php
// アスペクト比が4:3になっているDVファイルのヘッダを書き換えて16:9に変更する
define('SEARCH_BEGIN', 0x1C0);
define('SEARCH_END', 0x1D0);
define('FLAG_4_3', "\xC8");
define('FLAG_16_9', "\xCA");
if ($argc < 2) {
fwrite(STDERR, "Too few arguments.\n");
exit(1);
}
$file = $argv[1];
if (!is_file($file)) {
fwrite(STDERR, "File `{$file}' does not exist.\n");
exit(1);
}
if (filesize($file) < SEARCH_END) {
fwrite(STDERR, "File `$file' seems to be too small.\n");
exit(1);
}
$fp = fopen($file, 'rb+');
if (!$fp) {
fwrite(STDERR, "Cannot open file `{$file}' for writing.\n");
exit(1);
}
if (!flock($fp, LOCK_EX)) {
fwrite(STDERR, "Cannot lock file.\n");
fclose($fp);
exit(1);
}
$changed = false;
$pos = SEARCH_BEGIN;
fseek($fp, $pos);
while (!feof($fp) && $pos < SEARCH_END) {
$c = fread($fp, 1);
if ($c === FLAG_4_3) {
fseek($fp, -1, SEEK_CUR);
fwrite($fp, FLAG_16_9);
printf("Found at offset 0x%0X.\n", $pos);
$changed = true;
break;
}
$pos++;
}
flock($fp, LOCK_UN);
fclose($fp);
if ($changed) {
echo "OK.\n";
} else {
echo "Not modified.\n";
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment