normaliseParams( $file, $params ) ) { return new TransformParameterError( $params ); } $srcWidth = $file->getWidth(); $srcHeight = $file->getHeight(); // Audio should not be transformed by size, give it a default width and height if ( $this->isAudio( $file ) ) { $srcWidth = 220; $srcHeight = 23; } $params['width'] = isset( $params['width'] ) ? $params['width'] : $srcWidth; // if height overtakes width use height as max: $targetWidth = $params['width']; $targetHeight = $srcWidth == 0 ? $srcHeight : round( $params['width'] * $srcHeight / $srcWidth ); if ( isset( $params['height'] ) && $targetHeight > $params['height'] ) { $targetHeight = $params['height']; $targetWidth = round( $params['height'] * $srcWidth / $srcHeight ); } $options = [ 'file' => $file, 'length' => $this->getLength( $file ), 'offset' => $this->getOffset( $file ), 'width' => $targetWidth, 'height' => $targetHeight, 'isVideo' => !$this->isAudio( $file ), 'thumbtime' => isset( $params['thumbtime'] ) ? $params['thumbtime'] : intval( $file->getLength() / 2 ), 'start' => isset( $params['start'] ) ? $params['start'] : false, 'end' => isset( $params['end'] ) ? $params['end'] : false, 'fillwindow' => isset( $params['fillwindow'] ) ? $params['fillwindow'] : false, 'disablecontrols' => isset( $params['disablecontrols'] ) ? $params['disablecontrols'] : false ]; // No thumbs for audio if ( !$options['isVideo'] ) { return new TimedMediaTransformOutput( $options ); } // Setup pointer to thumb arguments $options[ 'thumbUrl' ] = $dstUrl; $options[ 'dstPath' ] = $dstPath; $options[ 'path' ] = $dstPath; return new TimedMediaTransformOutput( $options ); } function getLength( $file ) { if ( $this->isAudio( $file ) ) { return 0.99875; } return 4.3666666666667; } function getBitRate( $file ) { if ( $this->isAudio( $file ) ) { return 41107; } return 590013; } function getWebType( $file ) { if ( $this->isAudio( $file ) ) { return "audio/ogg; codecs=\"vorbis\""; } return "video/ogg; codecs=\"theora\""; } function getFramerate( $file ) { if ( $this->isAudio( $file ) ) { return 0; } return 30; } }