Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP8 Decoder for SourceGuardian Encoder)
- *
- * @ Version : 8.1.0.9
- * @ Author : DeZender
- * @ Release on : 27.10.2023
- * @ Official site : http://DeZender.Net
- *
- */
- namespace App\Utils;
- class FFMpegCommandBuilder
- {
- protected $source = null;
- protected $isInternalRestream = null;
- protected $isHttpSource = null;
- protected $sourceInfo = null;
- protected $errorsOutput = null;
- protected $commandOutput = null;
- protected $params = [
- 'template' => [],
- 'initial' => [],
- 'fetch_options' => [],
- 'hwaccel' => [],
- 'source' => [],
- 'gen_pts' => [],
- 'read_native' => [],
- 'probesize' => [],
- 'progress' => [],
- 'analyzeduration' => [],
- 'remove_subs' => [],
- 'transcode' => [],
- 'transcode_rtmp' => [],
- 'meta_data' => [],
- 'subtitles' => [],
- 'map' => [],
- 'fingerprint_options' => [],
- 'fingerprint_format' => [],
- 'output' => [],
- 'concat' => [],
- 'ffmpeg_build' => []
- ];
- private mixed $ondemandProbesize;
- public function __construct($source, $isInternalRestream = false, $sourceInfo = [])
- {
- $this->source = $source;
- $this->isInternalRestream = $isInternalRestream;
- $this->sourceInfo = $sourceInfo;
- if (!empty($sourceInfo['fetch_options'])) {
- $this->addParams('fetch_options', $sourceInfo['fetch_options']);
- }
- $this->setSource($source);
- }
- protected function getTimestampsFromStream(\App\Models\Stream $stream): string
- {
- return ($stream->generate_timestamps ? '-fflags +genpts -async 1' : '-start_at_zero -copyts -vsync 0 -correct_ts_overflow 0 -avoid_negative_ts disabled -max_interleave_delta 0');
- }
- public function setTimestampsArchiveParams(): FFMpegCommandBuilder
- {
- $this->addParams('gen_pts', '-copyts -vsync 0 -correct_ts_overflow 0 -avoid_negative_ts disabled -max_interleave_delta 0');
- return $this;
- }
- public function setErrorsOutput($file): FFMpegCommandBuilder
- {
- $this->errorsOutput = $file;
- return $this;
- }
- public function setCommandOutput($file): FFMpegCommandBuilder
- {
- $this->commandOutput = $file;
- return $this;
- }
- public function setSource($source): FFMpegCommandBuilder
- {
- if ($this->isRtmpProtocol($source)) {
- $this->addParams('fetch_options', '-rtmp_live 1');
- }
- $this->isHttpSource = $this->isHttpProtocol($source);
- $this->addParams('source', sprintf('-i "%s"', $source));
- return $this;
- }
- public function setLogLevel(string $level): FFMpegCommandBuilder
- {
- $this->addParams('initial', sprintf('-loglevel %s', $level));
- return $this;
- }
- public function setProxy($proxy): FFMpegCommandBuilder
- {
- $this->addParams('fetch_options', sprintf('-http_proxy "%s"', (string) $proxy));
- return $this;
- }
- public function setUserAgent(string $userAgent): FFMpegCommandBuilder
- {
- $this->addParams('fetch_options', sprintf('-user_agent "%s"', $userAgent));
- return $this;
- }
- public function setFingerprint($text, $fontSize, $color, $x, $y, $useTimer = false)
- {
- if ($useTimer) {
- $text = $text . ' ' . date('H-i-s');
- }
- $this->addParams('fingerprint_options', ' -vf "drawtext=text=' . ('\'' . $text . '\'') . ':fontcolor=' . (string) $color . ':fontsize=' . (string) $fontSize . ':x=' . ($x . ':y=' . $y) . '"');
- return $this;
- }
- public function setFingerprintFormat($format, $vcodec, $output = '-')
- {
- $this->addParams('fingerprint_format', ' -vcodec ' . $vcodec . ' -preset ultrafast -codec:a copy -scodec copy -f mpegts ' . $output);
- return $this;
- }
- protected function getMapParamsFromStream(\App\Models\Stream $stream): string
- {
- if ($stream->type === \App\Models\Enum\StreamType::RADIO) {
- return '-map 0:a?';
- }
- $map = '';
- if ($stream->stream_all) {
- $map = $this->getDisposition($stream);
- }
- else if ($stream->custom_map->isNotEmpty()) {
- $map = $stream->custom_map->join(' ') . ' -copy_unknown';
- $map = preg_replace('(\\(.*\\))', '', $map);
- }
- if (!in_array($stream->type, [\App\Models\Enum\StreamType::EPISODE, \App\Models\Enum\StreamType::MOVIE]) && ($stream->read_settings->store_format ?? 'hls') == 'hls') {
- $map .= ' -sn';
- }
- return $map;
- }
- protected function getReadNativeParamFromStream(\App\Models\Stream $stream): string
- {
- if ($stream->read_native) {
- return '-re';
- }
- return '';
- }
- public function setProbesize($value = 5000000): FFMpegCommandBuilder
- {
- $value = $value ?? 5000000;
- $this->params['probesize'] = [];
- $this->addParams('probesize', sprintf('-probesize %s', $value));
- return $this;
- }
- public function addSubtitles($params): FFMpegCommandBuilder
- {
- $this->addParams('subtitles', $params);
- if (!empty($params)) {
- ..................................................................
- ........................................
- ....................
Advertisement
Add Comment
Please, Sign In to add comment