Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ciencia/9fb26f1d5a1557b4c4bf3e96cf6d985b to your computer and use it in GitHub Desktop.
Save ciencia/9fb26f1d5a1557b4c4bf3e96cf6d985b to your computer and use it in GitHub Desktop.
patch MediaWiki extension TimedMediaHandler enable alpha transcodes REL1_39
diff --git a/includes/WebVideoTranscode/WebVideoTranscodeJob.php b/includes/WebVideoTranscode/WebVideoTranscodeJob.php
index df24861a..6849a0e9 100644
--- a/includes/WebVideoTranscode/WebVideoTranscodeJob.php
+++ b/includes/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -14,6 +14,7 @@ use FSFile;
use Job;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
+use MediaWiki\TimedMediaHandler\Handlers\WebMHandler\WebMHandler;
use MediaWiki\TimedMediaHandler\TimedMediaHandler;
use TempFSFile;
use Title;
@@ -389,6 +390,24 @@ class WebVideoTranscodeJob extends Job {
}
}
+ /**
+ * Adds input codec information for more accurate input codec selection
+ */
+ private function getInputCodec() {
+ $file = $this->getFile();
+ $handler = $file->getHandler();
+ if ( $handler instanceof WebMHandler ) {
+ $streams = $handler->getStreamTypes( $file );
+ if ( in_array( 'VP9', $streams ) ) {
+ // In order to carry out vp9 alpha channel to transcodes,
+ // it's necessary to specify the input codec as vp9,
+ // otherwise the default vp8 gets selected
+ return ' -vcodec libvpx-vp9';
+ }
+ }
+ return '';
+ }
+
/**
* Utility helper for ffmpeg mapping
* @param array $options
@@ -402,10 +421,12 @@ class WebVideoTranscodeJob extends Job {
return "source file is missing, " . $this->getSourceFilePath() . ". Encoding failed.";
}
+ $inputCodec = $this->getInputCodec();
+
// Set up the base command
$cmd = wfEscapeShellArg(
$wgFFmpegLocation
- ) . ' -nostdin -y -i ' . wfEscapeShellArg( $this->getSourceFilePath() );
+ ) . " -nostdin -y $inputCodec -i " . wfEscapeShellArg( $this->getSourceFilePath() );
if ( isset( $options['vpre'] ) ) {
$cmd .= ' -vpre ' . wfEscapeShellArg( $options['vpre'] );
@@ -588,7 +609,8 @@ class WebVideoTranscodeJob extends Job {
// Force to 4:2:0 chroma subsampling. Others are supported in Theora
// and in VP9 profile 1, but Chrome and Edge don't grok them.
- $cmd .= ' -pix_fmt yuv420p';
+ // yuva420p allows alpha channel
+ $cmd .= ' -pix_fmt yuva420p';
// Check for video quality:
if ( isset( $options['videoQuality'] ) && $options['videoQuality'] >= 0 ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment