Skip to content

Commit

Permalink
Do not create extra block
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Jun 19, 2023
1 parent 950cf36 commit 26a23d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Code/Converters/SccConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public function internalFormatToFileContent(array $internal_format)
{
$file_content = "Scenarist_SCC V1.0\r\n\r\n";

foreach ($internal_format as $block) {
$file_content .= self::textToSccLine($block['start'], $block['end'], $block['lines']);
foreach ($internal_format as $k => $block) {
$next_block = isset($internal_format[$k + 1]) ? $internal_format[$k + 1] : null;
$file_content .= self::textToSccLine($block['start'], $block['end'], $block['lines'], $next_block);
}

return $file_content;
Expand Down Expand Up @@ -113,7 +114,7 @@ protected static function internalTimeToScc($internal_time)
// 94d0 above the last one
// 1370 above the 94d0
// 13d0 above the 1370
protected static function textToSccLine($start, $end, $lines)
protected static function textToSccLine($start, $end, $lines, $next_block)
{
$lines = self::splitLongLines($lines);

Expand All @@ -130,7 +131,16 @@ protected static function textToSccLine($start, $end, $lines)
$output .= ' ' . self::lineToText($line);
}
$output .= ' 942f 942f' . "\r\n\r\n";
$output .= self::internalTimeToScc($end) . "\t" . '942c 942c' . "\r\n\r\n";

// if the next block showing text right away, do not add the stop
if ($next_block !== null) {
if (($next_block['start'] - $end) * self::$fps > 1) { // add if more than 1 frame difference
$output .= self::internalTimeToScc($end) . "\t" . '942c 942c' . "\r\n\r\n";
}
} else {
// add stop block at the end of file
$output .= self::internalTimeToScc($end) . "\t" . '942c 942c' . "\r\n\r\n";
}

return $output;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/formats/SccTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,18 @@ public function testSplitLongLines()

}

public function testDoesntAddStopLineIfTimesAreTouching()
{
$expected = "Scenarist_SCC V1.0
00:00:01:00\t94ae 94ae 9420 9420 9470 9470 ef6e e580 942f 942f
00:00:02:00\t94ae 94ae 9420 9420 9470 9470 f4f7 ef80 942f 942f
00:00:03:00\t942c 942c
";
$actual = (new Subtitles())->add(1, 2, 'one')->add(2.01, 3, 'two')->content('scc');
$this->assertStringEqualsStringIgnoringLineEndings($expected, $actual);
}
}

0 comments on commit 26a23d8

Please sign in to comment.