PHP - wypisanie napisów do filmów z formatu STL

0

Witam

Czy ktoś wie jak wyciągnąć napisy do filmu z binarnego pliku o formacie STL ?

Potrzebowałbym wypisać na stronie zawartość w postacji np:

0001:20 0001:28 Dzień dobry
0001:34 0001:40 A witam witam
0001:59 0002:06 Co tam słychać ?
................

Pozdrawiam

0

Pokaż przykładowy plik.

0

podaję przykład

0

to jakieś binarne jest.
stl file format w google, przeanalizować, potem możliwe, że uda się to pociągnąć wyrażeniami regularnymi (czyli google: wyrażenia regularne, no i preg_match lub preg_replace)

0

Specyfikacja formatu EBU (1991 rok; przewiduje, że napisy znajdą się na dyskietce ;))
Przykładowy parser
Przykładowe wykorzystanie

Tak to wygląda

Aczkolwiek nie wiem o co chodzi z kodowaniem. Niby jest ono w pliku podane, ale jednak to nie to.

<?php

require 'EBUParser.php';

function formatTimecode(EBUTimeCode $timecode)
{
    return sprintf('%02d:%02d:%02d.%02d', $timecode->hour, $timecode->minute, $timecode->second, $timecode->frame);
}

function formatText($text, $codepage = null)
{
    if($codepage !== null)
        $text = iconv($codepage, 'utf-8', $text);

    return nl2br($text);
}

$filename = 'przyklad.stl';

$subtitles = \EBUParser::Parse($filename);

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
</head>
<body>
<table>
    <?php
    foreach($subtitles->subtitles as $subtitle) {
    ?>
    <tr>
        <td><?= formatTimecode($subtitle->timeCodeIn) ?></td>
        <td><?= formatTimecode($subtitle->timeCodeOut) ?></td>
        <td><?= formatText($subtitle->text, $subtitles->codepage) ?></td>
    </tr>
    <?php } ?>
</table>
</body>
</html>
class EBUTimeCode
{
    public $hour;
    public $minute;
    public $second;
    public $frame;

    public function __construct($stream)
    {
        $this->hour = self::GetNumber($stream);
        $this->minute = self::GetNumber($stream);
        $this->second = self::GetNumber($stream);
        $this->frame = self::GetNumber($stream);
    }

    private static function GetNumber($stream)
    {
        return ord(fread($stream, 1));
    }
}

class EBUSubtitle
{
    public $timeCodeIn;
    public $timeCodeOut;
    public $text;

    public function __construct($stream)
    {
        fseek($stream, 5, SEEK_CUR);
        $this->timeCodeIn = new EBUTimeCode($stream);
        $this->timeCodeOut = new EBUTimeCode($stream);

        fseek($stream, 3, SEEK_CUR);
        $this->text = self::GetSubtitleText($stream);
    }

    private function GetSubtitleText($stream)
    {
        $text = fread($stream, 112);

        $text = str_replace(chr(0x8a), "\n", $text);
        $text = trim($text, chr(0x8f));

        return $text;
    }
}

class EBUSubtitles
{
    public $codepage;
    public $subtitles;
}

class EBUParser
{
    public static function Parse($filename)
    {
        $subtitles = new \EBUSubtitles();

        $file = fopen($filename, 'rb');

        $subtitles->codepage = (int)fread($file, 3);

        fseek($file, 238);
        $subtitleCount = (int)fread($file, 5);

        fseek($file, 1024);
        for($i = 0; $i < $subtitleCount; $i++)
            $subtitles->subtitles[] = new \EBUSubtitle($file);

        print "\n";
        return $subtitles;
    }
}
0

REV - Działa poprawnie

wielkie dzięki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1