扩展:TimedMediaHandler

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Extension:TimedMediaHandler and the translation is 58% complete.

Other languages:
català • ‎Deutsch • ‎English • ‎español • ‎suomi • ‎français • ‎Frysk • ‎italiano • ‎日本語 • ‎Nederlands • ‎polski • ‎português • ‎português do Brasil • ‎русский • ‎sicilianu • ‎中文
MediaWiki扩展手册Manual:Extensions
Crystal Clear action run.png
TimedMediaHandler

发布状态:Extension status 稳定版

实现Template:Extension#type Media
描述Template:Extension#description 提供对于服务器端转码的集成支持,WebM、OGG Theora、Vorbis、Speex语音以及赋时文本
作者Template:Extension#username Michael Dale, Jan Gerber, Tim Starling, James Heinrich, Brion Vibber, Derk-Jan Hartman
最新版本Template:Extension#version 0.5.0 (2015-12-08)
MediaWikiTemplate:Extension#mediawiki 1.23+
PHPTemplate:Extension#php 5.3+
数据更新Template:Extension#needs-updatephp
许可协议Template:Extension#license GNU General Public License 2.0 or later
下载
使用的钩子Template:Extension#hook
ArticleFromTitleManual:Hooks/ArticleFromTitle
UploadCompleteManual:Hooks/UploadComplete
TitleMoveManual:Hooks/TitleMove
FileDeleteCompleteManual:Hooks/FileDeleteComplete
BeforePageDisplayManual:Hooks/BeforePageDisplay
ImageOpenShowImageInlineBeforeManual:Hooks/ImageOpenShowImageInlineBefore
ImagePageFileHistoryLineManual:Hooks/ImagePageFileHistoryLine
LoadExtensionSchemaUpdatesManual:Hooks/LoadExtensionSchemaUpdates
UnitTestsListManual:Hooks/UnitTestsList
ArticleContentOnDiffManual:Hooks/ArticleContentOnDiff
ImagePageAfterImageLinksManual:Hooks/ImagePageAfterImageLinks
NewRevisionFromEditCompleteManual:Hooks/NewRevisionFromEditComplete
ArticlePurgeManual:Hooks/ArticlePurge
wgQueryPagesManual:Hooks/wgQueryPages
RejectParserCacheValueManual:Hooks/RejectParserCacheValue

翻译TimedMediaHandler扩展(如果在translatewiki.net可用)

检查使用和版本矩阵。

问题Phabricator

开放的工作 · 报告错误

The TimedMediaHandler extension allows you to display audio and video files in wiki pages, using the same syntax as for image files. It includes the Kaltura HTML5 Player and and experimental VideoJS Player. There is support for subtitles and captions (aka Timed Text) and real time stream switching between multiple WebM and Ogg derivatives and many other features. TMH server side support includes options for uploading HTML5 audio and video, multiple transcode profiles to deliver content, Medata parsing for Ogg and WebM videos and integrates with mediaWiki's jobQueue system for scheduling transcoding jobs.

功能概览[edit]

查看Commons:Commons:TimedText页面。

语法简介[edit]

image embed syntax基础上,Timed Media Handler支持:

[[File:Video.ogv|File:Video.ogv]] 
用原尺寸显示一个视频。显示一个在视频中点提取的静止图像,和一个用来激活播放器的播放按钮。
[[File:Audio.oga|File:Audio.oga]]
为声音文件显示一个占位符,包含一个用于激活播放器的播放按钮。
[[File:Video.ogv|thumb]] 
在一个浮动的缩略图里显示视频。
<gallery>File:Video.ogv</gallery>
在一个图片库(image gallery)里嵌入视频(每一个截图都会弹出一个用于完整视频的对话框)。
[[File:Video.ogg|thumbtime=1:25]]
用1分25秒的一帧画面插入视频作为占位图形。一个单独的数字将默认被理解成秒数。
[[File:Video.ogg|start=1:25]]
Temporal media fragments Displays a video clip starting at 1 minute 25 seconds into the video. A single number is taken as an offset in seconds. You can also include an end time of the form end=1:30 Which would result in a clip of 5 seconds playing from 1:25 to 1:30. If thumbtime is not provided, the start time will be used for the displayed thumbnail.

客户端支持[edit]

示例视频播放器
示例音频播放器

这个播放器在大部分现代浏览器上能够工作,支持IE9及更高版本(在MediaWiki's support matrix里有关于现代浏览器的描述)。 移动端支持情况不一,尤其是在iOS上。

As of August 2015, TimedMediaHandler includes a JavaScript compatibility shim for Ogg audio/video that works in Safari, Internet Explorer 10/11, and Microsoft Edge browsers.

Third-party users of MediaWiki may also wish to manually enable MP4 H.264/AAC support for native video and audio playback in Safari/IE/Edge, but when using these formats you may need a patent license from MPEG-LA for internet broadcasting.

安装[edit]

请同时看README来了解详细安装指南。

You will want a recent version of ffmpeg in order to support encoding to WebM ( with the latest version of VP8) and a copy of ffmpeg2theora to encode ogg videos. j^ supplies up-to-date static builds of ffmpeg with WebM support and of ffmpeg2theora for major OSs at firefogg.org/nightly/


  • 下载文件,并将其放置在您extensions/文件夹中的TimedMediaHandler目录内。
  • 将下列代码放置在您的LocalSettings.php的底部:
// TimedMediaHandler is dependent on mwEmbedSupport 
require_once "$IP/extensions/MwEmbedSupport/MwEmbedSupport.php";
// TimedMediaHandler
require_once "$IP/extensions/TimedMediaHandler/TimedMediaHandler.php";
  • 运行更新脚本,它将自动创建此扩展必须依赖的数据库表。
  • YesY Done - 在您的wiki上导航至Special:Version,以验证扩展已成功安装。


The extension will automatically add supported file types (except mp4) to $wgFileExtensions, so you do not need to manually add video file types.

维基百科媒体编码选项的比较[edit]

Sorted by bandwidth tier (grayed items are not currently enabled):

Bitrate Mbit/s Ogg Theora WebM VP8 WebM VP9
Very Low 0.16 160p15 160p15
Low 0.25 240p 360p
Moderate 0.5 240p 360p 480p
Medium 1.0 360p 480p 720p
High 2.0 480p 720p 1080p
Very high 4.0 720p 1080p

Detailed options:

名称 160P 240P 360P 480P 720P 1080P 160P 360P 480P 720P 1080P 2160P 360P 480P 720P 1080P 2160P
容器 Ogg WebM
视频 编码 Theora VP8 VP9
Max width (pixels) 288 426 640 854 1280 1920 288 640 854 1280 1920 4096 640 854 1280 1920 4096
Max height (pixels) 160 240 360 480 720 1080 160 360 480 720 1080 2160 360 480 720 1080 2160
Bitrate (Mbit/s) 0.16 0.5 1.0 2.0 - -- 0.16 0.5 1.0 - - - - - - - -
品质 - - - - 6 6 - - - 7 7 - - - - - -
音频 编码 Vorbis Opus
频道 2 (stereo)
Sampling rate (Hz) 44100
品质 -1 1 1 2 3 - - 1 2 3 - - - - - - -

配置[edit]

这里展示了配置用变量和它们的默认值:

// Show a warning to the user if they are not using an html5 browser with high quality ogg support
$wgMwEmbedModuleConfig['EmbedPlayer.DirectFileLinkWarning'] = true;

// Show the options menu:
$wgMwEmbedModuleConfig['EmbedPlayer.EnableOptionsMenu'] = true;

// TMH needs java ( no h.264 or mp3 derivatives )
$wgMwEmbedModuleConfig['EmbedPlayer.DisableJava' ] = true;
$wgMwEmbedModuleConfig['EmbedPlayer.DisableHTML5FlashFallback' ] = true;

// The text interface should always be shown
// ( even if there are no text tracks for that asset at render time )
$wgMwEmbedModuleConfig['TimedText.ShowInterface'] = 'always';

// Show the add text link:
$wgMwEmbedModuleConfig['TimedText.ShowAddTextLink'] = true;

// How long you have to wait between transcode resets for non-error transcodes
$wgWaitTimeForTranscodeReset = 3600;

// The minimum size for an embed video player ( smaller than this size uses a pop-up player )
$wgMinimumVideoPlayerSize = 200;

// Set the supported ogg codecs:
$wgMediaVideoTypes = array( 'Theora', 'VP8' );
$wgMediaAudioTypes = array( 'Vorbis', 'Speex', 'FLAC', 'Opus' );

// Default skin for mwEmbed player
$wgVideoPlayerSkinModule = 'mw.PlayerSkinKskin';

// Support iframe for remote embedding
$wgEnableIframeEmbed = true;

// If transcoding is enabled for this wiki (if disabled, no transcode jobs are added and no
// transcode status is displayed). Note if remote embedding an asset we will still check if
// the remote repo has transcoding enabled and associated flavors for that media embed.
$wgEnableTranscode = true;

// If the job runner should run transcode commands in a background thread and monitor the
// transcoding progress. This enables more fine grain control of the transcoding process, wraps
// encoding commands in a lower priority 'nice' call, and kills long running transcodes that are
// not making any progress. If set to false, the job runner will use the more compatible
// php blocking shell exec command.
$wgEnableNiceBackgroundTranscodeJobs = false;

// The priority to be used with the nice transcode commands.
$wgTranscodeBackgroundPriority = 19;

// The total amout of time a transcoding shell command can take:
$wgTranscodeBackgroundTimeLimit = 3600 * 8;
// Maximum amount of virtual memory available to transcoding processes in KB
$wgTranscodeBackgroundMemoryLimit = 2 * 1024 * 1024; // 2GB avconv, ffmpeg2theora mmap resources so virtual memory needs to be high enough
// Maximum file size transcoding processes can create, in KB
$wgTranscodeBackgroundSizeLimit = 3 * 1024 * 1024; // 3GB

// Number of threads to use in avconv for transcoding
$wgFFmpegThreads = 1;

// The NS for TimedText (registered on MediaWiki.org)
// http://www.mediawiki.org/wiki/Extension_namespace_registration
// Note commons pre-dates TimedMediaHandler and should set $wgTimedTextNS = 102 in LocalSettings.php
$wgTimedTextNS = 710;

// Set TimedText namespace for ForeignDBViaLBRepo on a per wikiID basis
// $wgTimedTextForeignNamespaces = array( 'commonswiki' => 102 );
$wgTimedTextForeignNamespaces = array();

// Set to false to disable local TimedText,
// you still get subtitles for videos from foreign repos
// to disable all TimedText, set
// $wgMwEmbedModuleConfig['TimedText.ShowInterface'] = 'off';
$wgEnableLocalTimedText = true;

/**
 * Default enabled transcodes
 *
 * -If set to empty array, no derivatives will be created
 * -Derivative keys encode settings are defined in WebVideoTranscode.php
 *
 * -These transcodes are *in addition to* the source file.
 * -Only derivatives with smaller width than the source asset size will be created
 * -Regardless of source size at least one WebM and Ogg source will be created from the $wgEnabledTranscodeSet
 * -Derivative jobs are added to the MediaWiki JobQueue the first time the asset is displayed
 * -Derivative should be listed min to max
 */
$wgEnabledTranscodeSet = array(

	// WebM VP8/Vorbis
	// primary free/open video format
	// supported by Chrome/Firefox/Opera but not Safari/IE/Edge

	// Medium-bitrate web streamable WebM video
	WebVideoTranscode::ENC_WEBM_360P,

	// Moderate-bitrate web streamable WebM video
	WebVideoTranscode::ENC_WEBM_480P,

	// A high quality WebM stream
	WebVideoTranscode::ENC_WEBM_720P,

	// A full-HD high quality WebM stream
	WebVideoTranscode::ENC_WEBM_1080P,


	// Ogg Theora/Vorbis
	// Fallback for Safari/IE/Edge with ogv.js
	//
	// Requires twice the bitrate for same quality as VP8,
	// and JS decoder can be slow, so shift to smaller sizes.

	// Low-bitrate Ogg stream
	WebVideoTranscode::ENC_OGV_160P,

	// Medium-bitrate Ogg stream
	WebVideoTranscode::ENC_OGV_240P,

	// Moderate-bitrate Ogg stream
	WebVideoTranscode::ENC_OGV_360P,

	// High-bitrate Ogg stream
	WebVideoTranscode::ENC_OGV_480P,

/*
	// MP4 H.264/AAC
	// Primary format for the Apple/Microsoft world
	//
	// Check patent licensing issues in your country before use!
	// Similar to WebM in quality/bitrate

	// A least common denominator h.264 stream; first gen iPhone, iPods, early android etc.
	WebVideoTranscode::ENC_H264_320P,

	// A mid range h.264 stream; mid range phones and low end tables
	WebVideoTranscode::ENC_H264_480P,

	// An high quality HD stream; higher end phones, tablets, smart tvs
	WebVideoTranscode::ENC_H264_720P,

	// A full-HD high quality stream; higher end phones, tablets, smart tvs
	WebVideoTranscode::ENC_H264_1080P,
*/
);

$wgEnabledAudioTranscodeSet = array(
	WebVideoTranscode::ENC_OGG_VORBIS,

	//opus support must be available in avconv
	//WebVideoTranscode::ENC_OGG_OPUS,

	//avconv needs libmp3lame support
	//WebVideoTranscode::ENC_MP3,

	//avconv needs libvo_aacenc support
	//WebVideoTranscode::ENC_AAC,
);

// If mp4 source assets can be ingested:
$wgTmhEnableMp4Uploads = false;

// Two-pass encoding for .ogv Theora transcodes is flaky as of October 2015.
// Enable this only if testing with latest theora libraries!
// See tracking bug: https://phabricator.wikimedia.org/T115883
$wgTmhTheoraTwoPassEncoding = false;

// List of extensions handled by Timed Media Handler since its referenced in a few places.
// you should not modify this variable

$wgTmhFileExtensions = array( 'ogg', 'ogv', 'oga', 'flac', 'wav', 'webm', 'mp4' );

$wgFileExtensions = array_merge( $wgFileExtensions, $wgTmhFileExtensions );

//
// The following are deprecated or  no longer valid options in newer versions.
//

// Path override for cortado ( by default its false and uses hard coded paths relative to TMH
// or the predefined path on upload server: http://upload.wikimedia.org/jars/cortado.jar
// Removed in 1.26 and later
$wgCortadoJarFile = false;

如果需要转码,请确认你的$wgMaxShellMemory, $wgMaxShellTime, $wgMaxShellFileSize足够大而保证转码工作进行并保存输出。默认值很可能太小了。

进行转码工作[edit]

由于转码工作是资源集中型工作,它们不会再常规工作队列中运行 ( 查看 bug 29336 ) 。取而代之的是,它们必须在--类型变量里被要求。

php runJobs.php --type webVideoTranscode


编码节点[edit]

为了能够转码许多视频,你可能想要运行多个连接到主数据库并且直接访问你的文件的编码节点。如果你在使用ubuntu lucid (10.04) ,你需要添加this ppa并且安装php5-cli php-pear imagemagick ffmpeg ffmpeg2theora。

在 乌班图 12.04系统中的最小安装[edit]

add-apt-repository ppa:j/timedmediahandler
apt-get install php5-cli php-pear imagemagick ffmpeg ffmpeg2theora

在Localsettings.php文件中,添加PEAR的文件路径!

ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages:/usr/share/php");


路线图[edit]

  • Add api module for listing of derivatives ( done in TimedMediaHandler )
  • Add support for transcoding from arbitrary format uploads.
  • Improve transcoding tracking with database tables for registering failed transcodes, time taken per transcode, allow users to flag files as not playable or a visually broken transcodes.
  • Improve mobile support for uploading and playback ( via native aps if the browser html5 support does not include WebM )
  • Add support for WebM flattening of edited sequences
  • Add support for mp3 uploads and audio transcoding to mp3 and ogg. ( Off by default until mp3 patents expire in 2012 )
  • Add support for IE9 video tag WebM components
  • Add support for 1080p videos
  • *新增支持4k视频。
  • 新增支持8k视频。
  • 升级到2.x branch。 (On hold. Planning on switching to video.js.)
  • Change Kaultra player to Video.js as our main video player.

备注[edit]

These notes about the status of TimedMediaHandler were shared by Jan Gerber at the end of his consulting agreement for WMF on 27 September, 2013:

Since you asked in the last meeting to write up an overview of the current state of TimedMediaHandler, here we go:

  • videoscalers:
    • setup like jobrunners, but only processing video transcode jobs (configuration of jobs/memory/threads in puppet and wikimedia-config)
  • imagescalers:
    • extract frames from videos, using avconv for all videos reading videos via http from swift backend
  • proxy caches:
    • must support HTTP 206 Range Requests for video urls (currently requires custom code that is managed in puppet)
  • custom packages for video transcoding (apt.wikimedia.org):
    • ffmpeg2theora (new upstream version to reduce memory by only using one thread)
    • libav (ubuntu version with patch to fix memory leak in ogg decoder)
    • libvpx (new upstream version fixing various issues and quality improvements)
  • custom packages for image scaling (apt.wikimedia.org):
    • vips (new upstream version addressing various performance issues)

2015年8月更新[edit]

Brion and TheDJ are starting up some new maintenance on TImedMediaHandler:

Done:

  • fixed some regressions in transcode handling
  • added /ogv.js JavaScript compatibility shim for Safari 6.1+, IE 10/11, and Edge
  • increasing Ogg transcode quality (increased bandwidth)
  • 支持ogv.js中的子标题
  • finish killing broken Cortado Java compatibility shim
  • retooling TMH's ResourceLoader modules for better compatibility

Todo 'small':

  • fix more transcode issues
  • fix ogv.js issues
    • missing volume control

Todo 'medium':

  • get transcoding from VP9/Opus working on Wikimedia servers...
  • transcoding to VP9/Opus WebM with decreased bandwidth
  • add Ogg skeleton to ogg audio transcodes for better seeking
  • integrate lightweight video player into Extension:MobileFrontend
  • rework serving Timed Text

Todo 'large':

Todo 'long-term':

  • get VP9 working fast enough on ogv.js to replace Ogg Theora transcodes

另见[edit]