【问题标题】:How to display subtitles with an flv file in a web page?如何在网页中显示带有 flv 文件的字幕?
【发布时间】:2009-03-23 19:10:48
【问题描述】:

我已经为 mp4 格式的视频创建了字幕,我想将其作为 FLV 文件放到网上。 是否可以将字幕与flv文件一起播放而不将它们集成到视频图像中,因此保持它们为srt格式?

【问题讨论】:

    标签: flv flvplayback subtitle


    【解决方案1】:

    我找到了一种方法,使用 JW flv 播放器:

    1. 将您的 .srt 文件转换为 xml 文件(下面的 php 代码)
    2. 然后添加一个变量“captions”指向您的 xml 文件:

    s0.addVariable("captions","path/to/subtitles.xml");

    现场示例here

    // 将多行 srt 字幕文件转换为新格式 (02-05-08) tt XML 字幕文件的脚本 $use_cdata_tags = 真; $debug_output = 真; // 写入新文件的目录 // 它必须存在,可写,并且在被扫描的目录之外 $new_directory = '../temp/'; //////////////////////////////////////下面的用户配置\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\ // 如果是目录,则获取文件名或扫描目录 $filename = (isset($_GET["filename"])) ? strval($_GET["filename"]) : "./"; // 将每个文件读入一个数组 $it = new RecursiveDirectoryIterator("$filename"); foreach(new RecursiveIteratorIterator($it) as $file) { // 调试('文件名', $file);出口; // debug('Ext', substr(strtolower($file), (strlen($file) - 4), 4));// 退出; // 调试 - 只使用测试文件 // if($file == '.\multi-line_test_file.srt') // 检查 .srt 扩展名 if(substr(strtolower($file), (strlen($file) - 4), 4) == '.srt') { $ttxml = ''; $full_line = ''; 如果($file_array = 文件($file)) { // 为新文件写入 tt 、 head 和 div 元素 $ttxml .= ""; $ttxml .= "\n"; $ttxml .= " \n"; $ttxml .= " \n"; $ttxml .= " \n"; $ttxml .= " \n"; foreach($file_array 作为 $line) { $line = rtrim($line); // 调试('Line', $line); // 获取开始和结束 // 00 : 00 : 32 , 000 --> 00 : 00 : 37 , 000 if(preg_match('/(\d\d):(\d\d):(\d\d),(\d\d\d) --> (\d\d):(\d\d ):(\d\d),(\d\d\d)/', $line, $match)) { $begin = $match[1] 。 “:”。 $匹配[2]。 “:”。 $匹配[3]。 “。” . $匹配[4]; $end = $match[5] 。 “:”。 $匹配[6]。 “:”。 $匹配[7]。 “。” . $匹配[8]; $full_line = ''; } // 如果下一行不为空,则获取文本 elseif($line != '') { if($full_line != '') { $full_line .= '
    ' 。 $线; } 别的 { $full_line .= $line; } } // 如果下一行为空,则写入段落 if($line == '') { // 写新段落 // 什么都没有发生。 如果($use_cdata_tags) { $ttxml .= " \n"; } 别的 { $ttxml .= " " 。 $full_line 。 "\n"; } // 调试('文本', $line); // 调试('ttxml', $ttxml);出口; $full_line = ''; } } // 写结束标签 $ttxml .= " \n"; $ttxml .= " \n"; $ttxml .= "\n"; // 写入新文件 $new_file = $new_directory 。 substr($file, 0, (strlen($file) - 4)) 。 '.xml'; $fh = fopen($new_file, 'w') or die('Can\'t open: ' . $new_file); fwrite($fh, $ttxml) 或 die('Can\'t write to: ' . $new_file); fclose($fh); } } } 函数调试($title, $value) { 全局 $debug_output; 如果 ($debug_output) { 打印“
    ”;
        if (is_array($value))
        {
          打印 $title 。 ":\n";
          print_r($值);
        }
        别的
        {
          打印 $title 。 “:”。 $价值;
        }
        打印“
    \n”; } } ?>

    【讨论】:

      猜你喜欢
      • 2010-11-25
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-15
      • 2012-05-28
      • 2011-08-22
      相关资源
      最近更新 更多