Skip to content
Snippets Groups Projects
Unverified Commit 345058f7 authored by Andreas Gohr's avatar Andreas Gohr Committed by GitHub
Browse files

Merge pull request #2077 from schplurtz/vtt-tracks

Support Web Video Text Tracks Format subtitles
parents 680cee63 23c61bbe
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ wav audio/wav
webm video/webm
ogv video/ogg
mp4 video/mp4
vtt text/vtt
tgz !application/octet-stream
tar !application/x-gtar
......
......@@ -2460,4 +2460,39 @@ function media_supportedav($mime, $type=NULL){
return in_array($mime, $supportedAv);
}
/**
* Return track media files with the same base name
* but extensions that indicate kind and lang.
* ie for foo.webm search foo.sub.lang.vtt, foo.cap.lang.vtt...
*
* @param string $src - ID of media file
* @return array - array(mediaID => array( kind, srclang ))
*
* @author Schplurtz le Déboulonné <Schplurtz@laposte.net>
*/
function media_trackfiles($src){
$kinds=array(
'sub' => 'subtitles',
'cap' => 'captions',
'des' => 'descriptions',
'cha' => 'chapters',
'met' => 'metadata'
);
$files = array();
$re='/\\.(sub|cap|des|cha|met)\\.([^.]+)\\.vtt$/';
$baseid=pathinfo($src, PATHINFO_FILENAME);
$pattern=mediaFN($baseid).'.*.*.vtt';
$list=glob($pattern);
foreach($list as $track) {
if(preg_match($re, $track, $matches)){
$files[$baseid.'.'.$matches[1].'.'.$matches[2].'.vtt']=array(
$kinds[$matches[1]],
$matches[2],
);
}
}
return $files;
}
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
......@@ -1783,6 +1783,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
* Embed video(s) in HTML
*
* @author Anika Henke <anika@selfthinker.org>
* @author Schplurtz le Déboulonné <Schplurtz@laposte.net>
*
* @param string $src - ID of video to embed
* @param int $width - width of the video in pixels
......@@ -1800,6 +1801,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$posterUrl = '';
$files = array();
$tracks = array();
$isExternal = media_isexternal($src);
if ($isExternal) {
......@@ -1811,6 +1813,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$extensions = array('webm', 'ogv', 'mp4');
$files = media_alternativefiles($src, $extensions);
$poster = media_alternativefiles($src, array('jpg', 'png'));
$tracks = media_trackfiles($src);
if(!empty($poster)) {
$posterUrl = ml(reset($poster), '', true, '&');
}
......@@ -1839,6 +1842,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer {
$fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true);
}
// output each track if any
foreach( $tracks as $trackid => $info ) {
list( $kind, $srclang ) = array_map( 'hsc', $info );
$out .= "<track kind=\"$kind\" srclang=\"$srclang\" ";
$out .= "label=\"$srclang\" ";
$out .= 'src="'.ml($trackid, '', true).'">'.NL;
}
// finish
$out .= $fallback;
$out .= '</video>'.NL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment