swf2ass/swf2ass.php

62 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . "/vendor/autoload.php";
const SWFMILL_BINARY = "swfmill";
const TWIP_SIZE = 20;
const ADVANCED_MOTION_INTERPOLATION = true;
ob_start();
passthru(escapeshellarg(SWFMILL_BINARY) . " swf2xml " . escapeshellarg($argv[1]) . " stdout");
$contents = ob_get_contents();
ob_end_clean();
$swf = new \DOMDocument();
$swf->loadXML($contents);
$soundStream = "";
$fp = fopen($argv[2], "w+");
fwrite($fp, <<<ASSHEADER
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: TV.709
PlayResX: 480
PlayResY: 360
[Aegisub Project Garbage]
Last Style Storage: Default
Video File: ?dummy:60.000000:10000:960:720:160:160:160:c
Video AR Value: 1.333333
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: f,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
ASSHEADER
);
$headerTag = $swf->getElementsByTagName("Header")->item(0);
if ($headerTag instanceof DOMElement) {
foreach (\swf2ass\Utils::processSWF($headerTag, $soundStream) as $line) {
fwrite($fp, $line);
};
}
/*
if($soundStream !== ""){
file_put_contents($argv[2] . ".mp3", $soundStream);
}*/