HLSExporter
extends MediaExporter
in package
uses
EncryptsHLSSegments
Table of Contents
Constants
- ENCRYPTION_LISTENER = "listen-encryption-key"
- HLS_KEY_INFO_FILENAME = 'hls_encryption.keyinfo'
Properties
- $concatWithAudio : bool
- $concatWithTranscoding : bool
- $concatWithVideo : bool
- $driver : PHPFFMpeg
- $lastPercentage : float
- $lastRemaining : float
- $maps : Collection
- $mustBeAccurate : bool
- $onProgressCallback : Closure
- $returnFrameContents : bool
- $timelapseFramerate : float
- $visibility : string
- $encryptionIV : string
- Encryption IV
- $encryptionKey : string
- The encryption key.
- $encryptionKeyFilename : string
- The encryption key filename.
- $encryptionSecretsRoot : mixed
- Disk to store the secrets.
- $keyFrameInterval : int
- $listener : StdListener
- Listener that will rotate the key.
- $nextEncryptionFilenameAndKey : array<string|int, mixed>
- A fresh filename and encryption key for the next round.
- $onNewEncryptionKey : callable
- Gets called whenever a new encryption key is set.
- $pendingFormats : Collection
- $playlistGenerator : PlaylistGenerator
- $rotateEncryptiongKey : bool
- Wether to rotate the key on every segment.
- $segmentFilenameGenerator : Closure
- $segmentLength : int
- $segmentsOpened : int
- Number of opened segments.
- $segmentsPerKey : int
- Number of segments that can use the same key.
Methods
- __call() : mixed
- Forwards the call to the driver object and returns the result if it's something different than the driver object itself.
- __construct() : mixed
- accurate() : self
- addFormat() : self
- Initializes the $pendingFormats property when needed and adds the format with the optional callback to add filters.
- addFormatOutputMapping() : mixed
- addTileFilter() : self
- Calls the callable with a TileFactory instance and adds the freshly generated TileFilter.
- afterSaving() : self
- Adds a callable to the callbacks array.
- asTimelapseWithFramerate() : self
- concatWithTranscoding() : self
- dd() : void
- Dump the final command and end the script.
- generateEncryptionKey() : string
- Creates a new encryption key.
- generateEncryptionKeyFilename() : string
- Creates a new encryption key filename.
- generateTemporarySegmentPlaylistFilename() : string
- Returns the filename of a segment playlist by its key. We let FFmpeg generate a playlist for each added format so we don't have to detect the bitrate and codec ourselves.
- getAccuracy() : bool
- getCommand() : mixed
- Prepares the saves command but returns the command instead.
- getFrameContents() : string
- getProcessOutput() : ProcessOutput
- inFormat() : self
- onProgress() : HasProgressListener|MediaExporter
- Setter for the callback.
- save() : MediaOpener
- Runs the export, generates the main playlist, and cleans up the segment playlist guides and temporary HLS encryption keys.
- setKeyFrameInterval() : self
- Setter for the Key Frame interval
- setSegmentLength() : self
- Setter for the segment length
- toDisk() : mixed
- unaccurate() : self
- useSegmentFilenameGenerator() : self
- Setter for a callback that generates a segment filename.
- withEncryptionKey() : HLSExporter|EncryptsHLSSegments
- Initialises the disk, info and IV for encryption and sets the key.
- withPlaylistGenerator() : self
- Method to set a different playlist generator than the default HLSPlaylistGenerator.
- withRotatingEncryptionKey() : HLSExporter|EncryptsHLSSegments
- Enables encryption with rotating keys. The callable will receive every new key and the integer sets the number of segments that can use the same key.
- withVisibility() : mixed
- addTimelapseParametersToFormat() : mixed
- getDisk() : Disk
- getMediaOpener() : MediaOpener
- runAfterSavingCallbacks() : mixed
- addConcatFilterAndMapping() : mixed
- addHandlerToRotateEncryptionKey() : void
- Adds a listener and handler to rotate the key on every new HLS segment.
- addHLSParametersToFormat() : array<string|int, mixed>
- Merges the HLS parameters to the given format.
- applyFiltersCallback() : array<string|int, mixed>
- Gives the callback an HLSVideoFilters object that provides addFilter(), addLegacyFilter(), addWatermark() and resize() helper methods. It returns a mapping for the video and (optional) audio stream.
- applyProgressListenerToFormat() : void
- Only calls the callback if the percentage is below 100 and is different from the previous emitted percentage.
- cleanupHLSEncryption() : HLSExporter|EncryptsHLSSegments
- Removes the encryption keys from the temporary disk.
- cleanupSegmentPlaylistGuides() : self
- Loops through each added format and then deletes the temporary segment playlist, which we generate manually using the HLSPlaylistGenerator.
- getEncrypedHLSParameters() : array<string|int, mixed>
- Returns an array with the encryption parameters.
- getPlaylistGenerator() : PlaylistGenerator
- getSegmentFilenameGenerator() : callable
- Returns a default generator if none is set.
- getSegmentPatternAndFormatPlaylistPath() : array<string|int, mixed>
- Calls the generator with the path (without extension), format and key.
- prepareSaving() : Collection
- Adds a mapping for each added format and automatically handles the mapping for filters. Adds a handler to rotate the encryption key (optional).
- removeHandlerThatRotatesEncryptionKey() : HLSExporter|EncryptsHLSSegments
- Remove the listener at the end of the export to prevent duplicate event handlers.
- replaceAbsolutePathsHLSEncryption() : HLSExporter|EncryptsHLSSegments
- While encoding, the encryption keys are saved to a temporary directory.
- rotateEncryptionKey() : string
- Rotates the key and returns the absolute path to the info file. This method should be executed as fast as possible, or we might be too late for FFmpeg opening the next segment. That's why we don't use the Disk-class magic.
Constants
ENCRYPTION_LISTENER
public
mixed
ENCRYPTION_LISTENER
= "listen-encryption-key"
HLS_KEY_INFO_FILENAME
public
mixed
HLS_KEY_INFO_FILENAME
= 'hls_encryption.keyinfo'
Properties
$concatWithAudio
protected
bool
$concatWithAudio
= false
$concatWithTranscoding
protected
bool
$concatWithTranscoding
= false
$concatWithVideo
protected
bool
$concatWithVideo
= false
$driver
protected
PHPFFMpeg
$driver
$lastPercentage
protected
float
$lastPercentage
$lastRemaining
protected
float
$lastRemaining
= 0
$maps
protected
Collection
$maps
$mustBeAccurate
protected
bool
$mustBeAccurate
= false
$onProgressCallback
protected
Closure
$onProgressCallback
$returnFrameContents
protected
bool
$returnFrameContents
= false
$timelapseFramerate
protected
float
$timelapseFramerate
$visibility
protected
string
$visibility
$encryptionIV
Encryption IV
private
string
$encryptionIV
$encryptionKey
The encryption key.
private
string
$encryptionKey
$encryptionKeyFilename
The encryption key filename.
private
string
$encryptionKeyFilename
$encryptionSecretsRoot
Disk to store the secrets.
private
mixed
$encryptionSecretsRoot
$keyFrameInterval
private
int
$keyFrameInterval
= 48
$listener
Listener that will rotate the key.
private
StdListener
$listener
$nextEncryptionFilenameAndKey
A fresh filename and encryption key for the next round.
private
array<string|int, mixed>
$nextEncryptionFilenameAndKey
$onNewEncryptionKey
Gets called whenever a new encryption key is set.
private
callable
$onNewEncryptionKey
$pendingFormats
private
Collection
$pendingFormats
$playlistGenerator
private
PlaylistGenerator
$playlistGenerator
$rotateEncryptiongKey
Wether to rotate the key on every segment.
private
bool
$rotateEncryptiongKey
= false
$segmentFilenameGenerator
private
Closure
$segmentFilenameGenerator
= null
$segmentLength
private
int
$segmentLength
= 10
$segmentsOpened
Number of opened segments.
private
int
$segmentsOpened
= 0
$segmentsPerKey
Number of segments that can use the same key.
private
int
$segmentsPerKey
= 1
Methods
__call()
Forwards the call to the driver object and returns the result if it's something different than the driver object itself.
public
__call(mixed $method, mixed $arguments) : mixed
Parameters
- $method : mixed
- $arguments : mixed
__construct()
public
__construct(PHPFFMpeg $driver) : mixed
Parameters
- $driver : PHPFFMpeg
accurate()
public
accurate() : self
Return values
selfaddFormat()
Initializes the $pendingFormats property when needed and adds the format with the optional callback to add filters.
public
addFormat(FormatInterface $format[, callable $filtersCallback = null ]) : self
Parameters
- $format : FormatInterface
- $filtersCallback : callable = null
Return values
selfaddFormatOutputMapping()
public
addFormatOutputMapping(FormatInterface $format, Media $output, array<string|int, mixed> $outs[, mixed $forceDisableAudio = false ][, mixed $forceDisableVideo = false ]) : mixed
Parameters
- $format : FormatInterface
- $output : Media
- $outs : array<string|int, mixed>
- $forceDisableAudio : mixed = false
- $forceDisableVideo : mixed = false
addTileFilter()
Calls the callable with a TileFactory instance and adds the freshly generated TileFilter.
public
addTileFilter(callable $withTileFactory) : self
Parameters
- $withTileFactory : callable
Return values
selfafterSaving()
Adds a callable to the callbacks array.
public
afterSaving(callable $callback) : self
Parameters
- $callback : callable
Return values
selfasTimelapseWithFramerate()
public
asTimelapseWithFramerate(float $framerate) : self
Parameters
- $framerate : float
Return values
selfconcatWithTranscoding()
public
concatWithTranscoding([bool $hasVideo = true ][, bool $hasAudio = true ]) : self
Parameters
- $hasVideo : bool = true
- $hasAudio : bool = true
Return values
selfdd()
Dump the final command and end the script.
public
dd([string $path = null ]) : void
Parameters
- $path : string = null
generateEncryptionKey()
Creates a new encryption key.
public
static generateEncryptionKey() : string
Return values
stringgenerateEncryptionKeyFilename()
Creates a new encryption key filename.
public
static generateEncryptionKeyFilename() : string
Return values
stringgenerateTemporarySegmentPlaylistFilename()
Returns the filename of a segment playlist by its key. We let FFmpeg generate a playlist for each added format so we don't have to detect the bitrate and codec ourselves.
public
static generateTemporarySegmentPlaylistFilename(int $key) : string
We use this as a reference so when can generate our own main playlist.
Parameters
- $key : int
Return values
stringgetAccuracy()
public
getAccuracy() : bool
Return values
boolgetCommand()
Prepares the saves command but returns the command instead.
public
getCommand([string $path = null ]) : mixed
Parameters
- $path : string = null
getFrameContents()
public
getFrameContents() : string
Return values
stringgetProcessOutput()
public
getProcessOutput() : ProcessOutput
Return values
ProcessOutputinFormat()
public
inFormat(FormatInterface $format) : self
Parameters
- $format : FormatInterface
Return values
selfonProgress()
Setter for the callback.
public
onProgress(Closure $callback) : HasProgressListener|MediaExporter
Parameters
- $callback : Closure
Return values
HasProgressListener|MediaExportersave()
Runs the export, generates the main playlist, and cleans up the segment playlist guides and temporary HLS encryption keys.
public
save([string $mainPlaylistPath = null ]) : MediaOpener
Parameters
- $mainPlaylistPath : string = null
Return values
MediaOpenersetKeyFrameInterval()
Setter for the Key Frame interval
public
setKeyFrameInterval(int $interval) : self
Parameters
- $interval : int
Return values
selfsetSegmentLength()
Setter for the segment length
public
setSegmentLength(int $length) : self
Parameters
- $length : int
Return values
selftoDisk()
public
toDisk(mixed $disk) : mixed
Parameters
- $disk : mixed
unaccurate()
public
unaccurate() : self
Return values
selfuseSegmentFilenameGenerator()
Setter for a callback that generates a segment filename.
public
useSegmentFilenameGenerator(Closure $callback) : self
Parameters
- $callback : Closure
Return values
selfwithEncryptionKey()
Initialises the disk, info and IV for encryption and sets the key.
public
withEncryptionKey(string $key[, string $filename = 'secret.key' ]) : HLSExporter|EncryptsHLSSegments
Parameters
- $key : string
- $filename : string = 'secret.key'
Return values
HLSExporter|EncryptsHLSSegmentswithPlaylistGenerator()
Method to set a different playlist generator than the default HLSPlaylistGenerator.
public
withPlaylistGenerator(PlaylistGenerator $playlistGenerator) : self
Parameters
- $playlistGenerator : PlaylistGenerator
Return values
selfwithRotatingEncryptionKey()
Enables encryption with rotating keys. The callable will receive every new key and the integer sets the number of segments that can use the same key.
public
withRotatingEncryptionKey(Closure $callback[, int $segmentsPerKey = 1 ]) : HLSExporter|EncryptsHLSSegments
Parameters
- $callback : Closure
- $segmentsPerKey : int = 1
Return values
HLSExporter|EncryptsHLSSegmentswithVisibility()
public
withVisibility(string $visibility) : mixed
Parameters
- $visibility : string
addTimelapseParametersToFormat()
protected
addTimelapseParametersToFormat() : mixed
getDisk()
protected
getDisk() : Disk
Return values
DiskgetMediaOpener()
protected
getMediaOpener() : MediaOpener
Return values
MediaOpenerrunAfterSavingCallbacks()
protected
runAfterSavingCallbacks([Media $outputMedia = null ]) : mixed
Parameters
- $outputMedia : Media = null
addConcatFilterAndMapping()
private
addConcatFilterAndMapping(Media $outputMedia) : mixed
Parameters
- $outputMedia : Media
addHandlerToRotateEncryptionKey()
Adds a listener and handler to rotate the key on every new HLS segment.
private
addHandlerToRotateEncryptionKey() : void
addHLSParametersToFormat()
Merges the HLS parameters to the given format.
private
addHLSParametersToFormat(DefaultAudio $format, string $segmentsPattern, Disk $disk, int $key) : array<string|int, mixed>
Parameters
- $format : DefaultAudio
- $segmentsPattern : string
- $disk : Disk
- $key : int
Return values
array<string|int, mixed>applyFiltersCallback()
Gives the callback an HLSVideoFilters object that provides addFilter(), addLegacyFilter(), addWatermark() and resize() helper methods. It returns a mapping for the video and (optional) audio stream.
private
applyFiltersCallback(callable $filtersCallback, int $formatKey) : array<string|int, mixed>
Parameters
- $filtersCallback : callable
- $formatKey : int
Return values
array<string|int, mixed>applyProgressListenerToFormat()
Only calls the callback if the percentage is below 100 and is different from the previous emitted percentage.
private
applyProgressListenerToFormat(EventEmitterInterface $format) : void
Parameters
- $format : EventEmitterInterface
cleanupHLSEncryption()
Removes the encryption keys from the temporary disk.
private
cleanupHLSEncryption() : HLSExporter|EncryptsHLSSegments
Return values
HLSExporter|EncryptsHLSSegmentscleanupSegmentPlaylistGuides()
Loops through each added format and then deletes the temporary segment playlist, which we generate manually using the HLSPlaylistGenerator.
private
cleanupSegmentPlaylistGuides(Media $media) : self
Parameters
- $media : Media
Return values
selfgetEncrypedHLSParameters()
Returns an array with the encryption parameters.
private
getEncrypedHLSParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>getPlaylistGenerator()
private
getPlaylistGenerator() : PlaylistGenerator
Return values
PlaylistGeneratorgetSegmentFilenameGenerator()
Returns a default generator if none is set.
private
getSegmentFilenameGenerator() : callable
Return values
callablegetSegmentPatternAndFormatPlaylistPath()
Calls the generator with the path (without extension), format and key.
private
getSegmentPatternAndFormatPlaylistPath(string $baseName, AudioInterface $format, int $key) : array<string|int, mixed>
Parameters
- $baseName : string
- $format : AudioInterface
- $key : int
Return values
array<string|int, mixed>prepareSaving()
Adds a mapping for each added format and automatically handles the mapping for filters. Adds a handler to rotate the encryption key (optional).
private
prepareSaving([string $path = null ]) : Collection
Returns a media collection of all segment playlists.
Parameters
- $path : string = null
Tags
Return values
CollectionremoveHandlerThatRotatesEncryptionKey()
Remove the listener at the end of the export to prevent duplicate event handlers.
private
removeHandlerThatRotatesEncryptionKey() : HLSExporter|EncryptsHLSSegments
Return values
HLSExporter|EncryptsHLSSegmentsreplaceAbsolutePathsHLSEncryption()
While encoding, the encryption keys are saved to a temporary directory.
private
replaceAbsolutePathsHLSEncryption(Collection $playlistMedia) : HLSExporter|EncryptsHLSSegments
With this method, we loop through all segment playlists and replace the absolute path to the keys to a relative ones.
Parameters
- $playlistMedia : Collection
Return values
HLSExporter|EncryptsHLSSegmentsrotateEncryptionKey()
Rotates the key and returns the absolute path to the info file. This method should be executed as fast as possible, or we might be too late for FFmpeg opening the next segment. That's why we don't use the Disk-class magic.
private
rotateEncryptionKey() : string