扩展:TimedMediaHandler

This page is a translated version of the page Extension:TimedMediaHandler and the translation is 61% complete.
Outdated translations are marked like this.
Other languages:
English • ‎dansk • ‎español • ‎français • ‎português do Brasil • ‎русский • ‎فارسی • ‎中文 • ‎日本語 • ‎한국어
MediaWiki扩展手册
OOjs UI icon advanced.svg
TimedMediaHandler
发布状态: 稳定版
Screenshot of TimedMediaHandler extension with Big Buck Bunny as background video.png
实现 媒体, API
描述 提供对于服务器端转码的集成支持,WebM、OGG Theora、Vorbis、Speex语音以及赋时文本
作者 Michael Dale, Jan Gerber, Tim Starling, James Heinrich, Brion Vibber, Derk-Jan Hartman
最新版本 0.6.0 (2018-11-07)
兼容性方针 发行分支
MediaWiki 1.29+
PHP 5.6+
数据庫更新
表格 transcode
许可协议 GNU通用公眾授權條款2.0或更新版本
下载
  • $wgMediaAudioTypes
  • $wgMediaVideoTypes
  • $wgWaitTimeForTranscodeReset
  • $wgEnableNiceBackgroundTranscodeJobs
  • $wgTmhEnableMp4Uploads
  • $wgUseFFmpeg2
  • $wgEnableTranscode
  • $wgTmhSoundfontLocation
  • $wgTmhWebPlayer
  • $wgTmhPriorityResolutionThreshold
  • $wgFFmpegVP9RowMT
  • $wgEnableIframeEmbed
  • $wgOggThumbLocation
  • $wgParserTestMediaHandlers
  • $wgTranscodeBackgroundSizeLimit
  • $wgTranscodeBackgroundTimeLimit
  • $wgTmhFluidsynthLocation
  • $wgTimedTextForeignNamespaces
  • $wgEnabledAudioTranscodeSet
  • $wgTmhFileExtensions
  • $wgEnabledTranscodeSet
  • $wgTmhUseBetaFeatures
  • $wgMinimumVideoPlayerSize
  • $wgFFmpegThreads
  • $wgMwEmbedModuleConfig
  • $wgTranscodeBackgroundMemoryLimit
  • $wgEnableLocalTimedText
  • $wgFFmpegLocation
  • $wgTmhPriorityLengthThreshold
  • $wgTimedTextNS
  • $wgTranscodeBackgroundPriority
  • transcode-reset
  • transcode-status
翻译TimedMediaHandler扩展如果在translatewiki.net可用
检查使用和版本矩阵。
问题 开放的工作 · 报告错误

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 an experimental VideoJS Player. There is support for subtitles and captions (aka Timed Text) and real time stream switching between multiple WebM and other derivatives and many other features. TMH server side support includes options for uploading HTML5 audio and video, multiple transcode profiles to deliver content, playback of MIDI files, metadata parsing for Ogg and WebM videos, and integration with MediaWiki's jobQueue system for scheduling transcoding jobs.

功能概览

查看Commons:Commons:Timed Text页面。

语法简介

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

[[File:Video.ogv|File:Video.ogv]]
用原尺寸显示一个视频。显示一个在视频中点提取的静止图像,和一个用来激活播放器的播放按钮。
[[File:Audio.oga|File:Audio.oga]]
为声音文件显示一个占位符,包含一个用于激活播放器的播放按钮。
[[File:Midi.mid]]
Generate digital audio from the music instructions in the MIDI file, and show the embedded audio player to play this audio.
[[File:Video.ogv|thumb]]
在一个浮动的缩略图里显示视频。
<gallery>File:Video.ogv</gallery>
在一个图片库(image gallery)里嵌入视频(每一个截图都会弹出一个用于完整视频的对话框)。
[[File:Video.ogg|thumbtime=1:25]]
用1分25秒的一帧画面插入视频作为占位图形。一个单独的数字将默认被理解成秒数。 也可以使用HH:MM:SS,例如1:02:22将是视频的1小时2分22秒。
[[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. One can also use HH:MM:SS, e.g. 1:02:22 will be 1 hour, 2 minutes, and 22 seconds into the video.
已弃用
The syntax words noicon and noplayer are deprecated and do not function. The keyword disablecontrols will likely be deprecated. (请参见Task 135537) It takes a comma-separated list of any of the following values: options, timedText, fullscreen

客户端支持

示例视频播放器
示例音频播放器
Wider audio player, showing progress bar

这个播放器在大部分现代浏览器上能够工作,支持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.

安装

You will want a recent version of ffmpeg in order to support encoding to WebM ( with the latest version of VP8). j^ supplies up-to-date static builds of ffmpeg with WebM support for major OSs at firefogg.org/nightly/. See the sections below for installation instructions on older versions of MediaWiki.

  • 下载文件,并将其放置在您extensions/文件夹中的TimedMediaHandler目录内。
  • 将下列代码放置在您的LocalSettings.php的底部:
    // MediaWiki 1.31 and later
    wfLoadExtension( 'TimedMediaHandler' );
    $wgFFmpegLocation = '/usr/bin/ffmpeg'; // Most common ffmpeg path on Linux
    
  • 运行更新脚本,它将自动创建此扩展必须依赖的数据库表。
  • This extension requires Composer to install PHP dependencies. Go to the extension directory and run composer install --no-dev.
  • Configure as required.
  • You may need to increase the allowed memory in $wgMaxShellMemory .
  •   完成 – 在您的wiki上导航至Special:Version,以验证扩展已成功安装。

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

After downloading this extension, please note that it requires Composer.

So, after installation change to the directory containing the extension e.g. "../extensions/TimedMediaHandler/" and run composer install --no-dev, or when updating: composer update --no-dev.

Alternatively as well as preferably add the line "extensions/TimedMediaHandler/composer.json" to the "composer.local.json" file in the root directory of your wiki like e.g.

{
	"extra": {
		"merge-plugin": {
			"include": [
				"extensions/TimedMediaHandler/composer.json"
			]
		}
	}
}

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

See Extension:TimedMediaHandler/VP9 transition for deployment details on planned Wikimedia update from VP8 to VP9.

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

Bitrate Mbit/s WebM VP8 WebM VP9
Super Low 0.08 160p
Very Low 0.16 160p 240p
Low 0.25 240p 360p
Moderate 0.5 360p 480p
Medium 1.0 480p 720p
High 2.0 720p 1080p
Very high 4.0 1080p 1440p
Super high 8.0 2160p

详细选项:

名称 160P 240P 360P 480P 720P 1080P 160P 240P 360P 480P 720P 1080P 1440P 2160P
容器 WebM
视频 编码 VP8 VP9
最大宽度(像素) 288 426 640 854 1280 1920 288 426 640 854 1280 1920 2560 4096
最大高度(像素) 160 240 360 480 720 1080 160 240 360 480 720 1080 1440 2160
比特率 (Mbit/s) 0.16 0.25 0.5 1.0 2.0 4.0 0.08 0.16 0.25 0.5 1.0 2.0 4.0 8.0
音频 编码 Vorbis Opus
频道 2 (stereo) (pass-through)
采样率 (Hz) 44100 48000
品质 - 1 2 3 - (default)

配置

本部分已过时-请更新我

这里展示了一些可能有用的配置变量:

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

// 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;

// 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)
// https://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();

/**
* 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 uploaded
* -Derivative should be listed min to max
*/
// Starting from 1.31
// All valid string values are listed in the extension's extension.json file 
$wgEnabledTranscodeSet = [
    '160p.webm' => true,
    '240p.webm' => true,
    '360p.webm' => true,
    '480p.webm' => true,
    '720p.webm' => true,
    '1080p.webm' => true,
];

$wgEnabledAudioTranscodeSet = [
    'vorbis' => true,
    'mp3' => true,
];

// If mp3 source assets can be ingested:
$wgTmhEnableMp3Uploads = true;

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

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

进行转码工作

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

php maintenance/runJobs.php --type webVideoTranscode

If running this command causes it to hang forever, you may need to set $wgTranscodeBackgroundTimeLimit = 0; in LocalSettings.php. 参见任务T206957

编码节点

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

在Debian和Ubuntu下的最小安装

apt install ffmpeg

Plus, add this to your LocalSettings.php (tested for Devuan ASCII only):

$wgFFmpegLocation = '/usr/bin/ffmpeg';

On older versions of MediaWiki (1.29–1.31)

  • Version 1.31 was breaking for system administrators. The extension now requires wfLoadExtension, dropped the dependency for the MwEmbedSupport extension, and the WebVideoTranscode PHP constants are now expressed as string values instead.
  • Note that, although MwEmbedSupport was included in TimedMediaHandler for MediaWiki 1.31 and later, for MediaWiki versions prior to that you will need to download it from the archive page.

In LocalSettings.php, load the extension with:

// MediaWiki 1.27 - 1.30
wfLoadExtension( 'MwEmbedSupport' );
require_once "$IP/extensions/TimedMediaHandler/TimedMediaHandler.php";

// <span class="mw-translate-fuzzy">TimedMediaHandler 依赖于 mwEmbedSupport</span>
// MediaWiki 1.27 and earlier
require_once "$IP/extensions/MwEmbedSupport/MwEmbedSupport.php";
require_once "$IP/extensions/TimedMediaHandler/TimedMediaHandler.php";

Prior to 1.31, $wgEnabledTranscodeSet is set with:

// Before 1.31
$wgEnabledTranscodeSet = [
    WebVideoTranscode::ENC_WEBM_160P,
    WebVideoTranscode::ENC_WEBM_240P,
    WebVideoTranscode::ENC_WEBM_360P,
    WebVideoTranscode::ENC_WEBM_480P,
    WebVideoTranscode::ENC_WEBM_720P,
    WebVideoTranscode::ENC_WEBM_1080P
];

$wgEnabledAudioTranscodeSet = [
    WebVideoTranscode::ENC_OGG_VORBIS,
    WebVideoTranscode::ENC_MP3,
];

Troubleshooting

This section needs expansion
"ffmpeg – failed to map segment from shared object"
You need to increase the allowed memory in $wgMaxShellMemory .
"Class 'getID3' not found"
You need to install the extension's PHP dependencies using Composer, see the Installation section above.