Guest User

Untitled

a guest
Jul 2nd, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP8 Decoder for SourceGuardian Encoder)
  6. *
  7. * @ Version : 8.1.0.9
  8. * @ Author : DeZender
  9. * @ Release on : 27.10.2023
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. namespace App\Utils;
  15.  
  16. class FFMpegCommandBuilder
  17. {
  18. protected $source = null;
  19. protected $isInternalRestream = null;
  20. protected $isHttpSource = null;
  21. protected $sourceInfo = null;
  22. protected $errorsOutput = null;
  23. protected $commandOutput = null;
  24. protected $params = [
  25. 'template' => [],
  26. 'initial' => [],
  27. 'fetch_options' => [],
  28. 'hwaccel' => [],
  29. 'source' => [],
  30. 'gen_pts' => [],
  31. 'read_native' => [],
  32. 'probesize' => [],
  33. 'progress' => [],
  34. 'analyzeduration' => [],
  35. 'remove_subs' => [],
  36. 'transcode' => [],
  37. 'transcode_rtmp' => [],
  38. 'meta_data' => [],
  39. 'subtitles' => [],
  40. 'map' => [],
  41. 'fingerprint_options' => [],
  42. 'fingerprint_format' => [],
  43. 'output' => [],
  44. 'concat' => [],
  45. 'ffmpeg_build' => []
  46. ];
  47. private mixed $ondemandProbesize;
  48.  
  49. public function __construct($source, $isInternalRestream = false, $sourceInfo = [])
  50. {
  51. $this->source = $source;
  52. $this->isInternalRestream = $isInternalRestream;
  53. $this->sourceInfo = $sourceInfo;
  54.  
  55. if (!empty($sourceInfo['fetch_options'])) {
  56. $this->addParams('fetch_options', $sourceInfo['fetch_options']);
  57. }
  58.  
  59. $this->setSource($source);
  60. }
  61.  
  62. protected function getTimestampsFromStream(\App\Models\Stream $stream): string
  63. {
  64. 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');
  65. }
  66.  
  67. public function setTimestampsArchiveParams(): FFMpegCommandBuilder
  68. {
  69. $this->addParams('gen_pts', '-copyts -vsync 0 -correct_ts_overflow 0 -avoid_negative_ts disabled -max_interleave_delta 0');
  70. return $this;
  71. }
  72.  
  73. public function setErrorsOutput($file): FFMpegCommandBuilder
  74. {
  75. $this->errorsOutput = $file;
  76. return $this;
  77. }
  78.  
  79. public function setCommandOutput($file): FFMpegCommandBuilder
  80. {
  81. $this->commandOutput = $file;
  82. return $this;
  83. }
  84.  
  85. public function setSource($source): FFMpegCommandBuilder
  86. {
  87. if ($this->isRtmpProtocol($source)) {
  88. $this->addParams('fetch_options', '-rtmp_live 1');
  89. }
  90.  
  91. $this->isHttpSource = $this->isHttpProtocol($source);
  92. $this->addParams('source', sprintf('-i "%s"', $source));
  93. return $this;
  94. }
  95.  
  96. public function setLogLevel(string $level): FFMpegCommandBuilder
  97. {
  98. $this->addParams('initial', sprintf('-loglevel %s', $level));
  99. return $this;
  100. }
  101.  
  102. public function setProxy($proxy): FFMpegCommandBuilder
  103. {
  104. $this->addParams('fetch_options', sprintf('-http_proxy "%s"', (string) $proxy));
  105. return $this;
  106. }
  107.  
  108. public function setUserAgent(string $userAgent): FFMpegCommandBuilder
  109. {
  110. $this->addParams('fetch_options', sprintf('-user_agent "%s"', $userAgent));
  111. return $this;
  112. }
  113.  
  114. public function setFingerprint($text, $fontSize, $color, $x, $y, $useTimer = false)
  115. {
  116. if ($useTimer) {
  117. $text = $text . ' ' . date('H-i-s');
  118. }
  119.  
  120. $this->addParams('fingerprint_options', ' -vf "drawtext=text=' . ('\'' . $text . '\'') . ':fontcolor=' . (string) $color . ':fontsize=' . (string) $fontSize . ':x=' . ($x . ':y=' . $y) . '"');
  121. return $this;
  122. }
  123.  
  124. public function setFingerprintFormat($format, $vcodec, $output = '-')
  125. {
  126. $this->addParams('fingerprint_format', ' -vcodec ' . $vcodec . ' -preset ultrafast -codec:a copy -scodec copy -f mpegts ' . $output);
  127. return $this;
  128. }
  129.  
  130. protected function getMapParamsFromStream(\App\Models\Stream $stream): string
  131. {
  132. if ($stream->type === \App\Models\Enum\StreamType::RADIO) {
  133. return '-map 0:a?';
  134. }
  135.  
  136. $map = '';
  137.  
  138. if ($stream->stream_all) {
  139. $map = $this->getDisposition($stream);
  140. }
  141. else if ($stream->custom_map->isNotEmpty()) {
  142. $map = $stream->custom_map->join(' ') . ' -copy_unknown';
  143. $map = preg_replace('(\\(.*\\))', '', $map);
  144. }
  145. if (!in_array($stream->type, [\App\Models\Enum\StreamType::EPISODE, \App\Models\Enum\StreamType::MOVIE]) && ($stream->read_settings->store_format ?? 'hls') == 'hls') {
  146. $map .= ' -sn';
  147. }
  148.  
  149. return $map;
  150. }
  151.  
  152. protected function getReadNativeParamFromStream(\App\Models\Stream $stream): string
  153. {
  154. if ($stream->read_native) {
  155. return '-re';
  156. }
  157.  
  158. return '';
  159. }
  160.  
  161. public function setProbesize($value = 5000000): FFMpegCommandBuilder
  162. {
  163. $value = $value ?? 5000000;
  164. $this->params['probesize'] = [];
  165. $this->addParams('probesize', sprintf('-probesize %s', $value));
  166. return $this;
  167. }
  168.  
  169. public function addSubtitles($params): FFMpegCommandBuilder
  170. {
  171. $this->addParams('subtitles', $params);
  172.  
  173. if (!empty($params)) {
  174. ..................................................................
  175. ........................................
  176. ....................
Advertisement
Add Comment
Please, Sign In to add comment