Implement Timer speed and time precision (although useless as libass fails at both)
This commit is contained in:
parent
b7030433d8
commit
f3255b57ac
|
@ -147,11 +147,11 @@ class ASSLine {
|
|||
return $layer;
|
||||
}
|
||||
|
||||
public function encode($frameDurationMs): string {
|
||||
if($frameDurationMs === 1000 and $this->cachedEncode !== null){
|
||||
public function encode($frameDurationMs, int $msPrecision = 2): string {
|
||||
if($frameDurationMs === 1000 and $msPrecision === 2 and $this->cachedEncode !== null){
|
||||
return $this->cachedEncode;
|
||||
}
|
||||
$line = ($this->isComment ? "Comment" : "Dialogue") . ": " . $this->getPackedLayer() . "," . self::encodeTime($this->start * $frameDurationMs) . "," . self::encodeTime(($this->end + 1) * $frameDurationMs) . "," . $this->style . "," . $this->name . "," . $this->marginLeft . "," . $this->marginRight . "," . $this->marginVertical . "," . $this->effect . ",";
|
||||
$line = ($this->isComment ? "Comment" : "Dialogue") . ": " . $this->getPackedLayer() . "," . self::encodeTime($this->start * $frameDurationMs, $msPrecision) . "," . self::encodeTime(($this->end + 1) * $frameDurationMs, $msPrecision) . "," . $this->style . "," . $this->name . "," . $this->marginLeft . "," . $this->marginRight . "," . $this->marginVertical . "," . $this->effect . ",";
|
||||
foreach ($this->tags as $tag){
|
||||
$line .= "{" . $tag->encode($this, $frameDurationMs) . "}";
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class ASSLine {
|
|||
return $line;
|
||||
}
|
||||
|
||||
public function equalish(ASSLine $line){
|
||||
public function equalish(ASSLine $line): bool {
|
||||
return $this->layer === $line->layer and $this->objectId === $line->objectId and count($this->tags) === count($line->tags) and $this->encode(1000) === $line->encode(1000);
|
||||
}
|
||||
}
|
|
@ -30,16 +30,20 @@ class ASSRenderer {
|
|||
$frameRate *= 2;
|
||||
}
|
||||
|
||||
$timerPrecision = str_replace(".", ",", sprintf("%.4F", (100 / $this->getSetting("timerSpeed", 100)) * 100));
|
||||
|
||||
$this->header = <<<ASSHEADER
|
||||
[Script Info]
|
||||
; Script generated by swf2ass ASSRenderer
|
||||
; https://git.gammaspectra.live/WeebDataHoarder/swf2ass
|
||||
ScriptType: v4.00+
|
||||
; TODO: maybe set WrapStyle: 2
|
||||
WrapStyle: 0
|
||||
ScaledBorderAndShadow: yes
|
||||
YCbCr Matrix: PC.709
|
||||
PlayResX: {$width}
|
||||
PlayResY: {$height}
|
||||
Timer: {$timerPrecision}
|
||||
|
||||
[Aegisub Project Garbage]
|
||||
Last Style Storage: Default
|
||||
|
@ -111,7 +115,7 @@ ASSHEADER;
|
|||
foreach ($this->runningBuffer as $line) {
|
||||
$line->name .= " f:{$line->start}>{$line->end}~".($line->end - $line->start + 1);
|
||||
$line->dropCache();
|
||||
yield $line->encode($information->getFrameDurationMilliSeconds());
|
||||
yield $line->encode($information->getFrameDurationMilliSeconds() * ($this->getSetting("timerSpeed", 100) / 100), $this->getSetting("timePrecision"));
|
||||
}
|
||||
|
||||
$this->runningBuffer = $runningBuffer;
|
||||
|
@ -121,7 +125,7 @@ ASSHEADER;
|
|||
foreach ($this->runningBuffer as $line) {
|
||||
$line->name .= " f:{$line->start}>{$line->end}~".($line->end - $line->start + 1);
|
||||
$line->dropCache();
|
||||
yield $line->encode($information->getFrameDurationMilliSeconds());
|
||||
yield $line->encode($information->getFrameDurationMilliSeconds() * ($this->getSetting("timerSpeed", 100) / 100), $this->getSetting("timePrecision"));
|
||||
}
|
||||
$this->runningBuffer = [];
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ $fp = fopen($argv[2], "w+");
|
|||
if ($swf->header["signature"]) {
|
||||
$processor = new \swf2ass\SWFProcessor($swf);
|
||||
$assRenderer = new \swf2ass\ass\ASSRenderer($processor->getFrameRate(), $processor->getViewPort(), [
|
||||
"bakeTransforms" => false //TODO: fix ASS matrix transform rendering and remove this
|
||||
"bakeTransforms" => false, //TODO: fix ASS matrix transform rendering and remove this
|
||||
"timerSpeed" => 100, //NOTE: libass does not implement "Timer:", which is used by this setting. Leave at 100 by default
|
||||
"timePrecision" => 2, //NOTE: libass does not implement anything different from 2. Leave at 2 by default
|
||||
]);
|
||||
|
||||
$keyFrameInterval = 10 * $processor->getFrameRate(); //kf every 10 seconds TODO: make this dynamic, per-shape
|
||||
|
|
Loading…
Reference in a new issue