2016-10-25 10 views
3

私はこのようなような入力を持っている:SRT秒、持続時間の変換(字幕)時刻形式(PHP)

start: 10 | duration: 1 | text: Subtitle Text 1 
start: 15 | duration: 2 | text: Subtitle Text 2 
start: 20 | duration: 3 | text: Subtitle Text 3 

それは、次の言う字幕命令セット、です:

At 10 second of the video, show "Subtitle Text 1" for 1 seconds 
At 15 second of the video, show "Subtitle Text 2" for 2 seconds 
At 20 second of the video, show "Subtitle Text 3" for 3 seconds 

この入力はSRT形式に変換する必要がありますので、次のようになります:

1 
00:00:10,000 --> 00:00:11,000 
Subtitle Text 1 

2 
00:00:15,000 --> 00:00:17,000 
Subtitle Text 2 

3 
00:00:20,000 --> 00:00:23,000 
Subtitle Text 3 

PHPを使用して、任意の秒の値をSRT形式(00:00:00,000)に変換する方法を教えてください。

これは私が本当に必要なすべてです。残りの部分は自分で分かります。

ありがとうございました。

答えて

1

私は最終的にこれは、上記のスクリプトに基づいて、自分自身の関数であるhttps://stackoverflow.com/a/4763921/998415

から助けを借りて、それを考え出した:

function seconds2SRT($seconds) 
{ 
    $hours = 0; 
    $milliseconds = str_replace("0.", '', $seconds - floor($seconds)); 

    if ($seconds > 3600) 
    { 
    $hours = floor($seconds/3600); 
    } 
    $seconds = $seconds % 3600; 


    return str_pad($hours, 2, '0', STR_PAD_LEFT) 
     . gmdate(':i:s', $seconds) 
     . ($milliseconds ? ",$milliseconds" : '') 
    ; 
} 

それはこのデモでの作業を参照してください:https://eval.in/665896

0

あなたは次のような字幕を作成できます:

$subtitles = new Subtitles(); 
$subtitles->add(10, 11, 'Subtitle Text 1'); 
$subtitles->add(15, 17, 'Subtitle Text 2'); 
$subtitles->add(20, 23, 'Subtitle Text 3'); 
echo $subtitles->content('srt'); 

// or if you need file 
$subtitles->save('subtitle-file.srt'); 

このライブラリをダウンロードする必要があります:https://github.com/mantas-done/subtitles

関連する問題