Conditions | 8 |
Paths | 36 |
Total Lines | 60 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
36 | private function HLSFilter(HLS $media) |
||
37 | { |
||
38 | $filter = []; |
||
39 | $total_count = count($representations = $media->getRepresentations()); |
||
40 | $counter = 0; |
||
41 | $path_parts = $media->getPathInfo(); |
||
42 | $dirname = str_replace("\\", "/", $path_parts["dirname"]); |
||
43 | $filename = substr($path_parts["filename"], -50); |
||
44 | $ts_sub_dir = Helper::appendSlash($media->getTsSubDirectory()); |
||
45 | $base_url = Helper::appendSlash($media->getHlsBaseUrl()); |
||
46 | |||
47 | if ($ts_sub_dir) { |
||
48 | FileManager::makeDir($dirname . DIRECTORY_SEPARATOR . $ts_sub_dir); |
||
49 | $base_url = $base_url . $media->getTsSubDirectory() . "/"; |
||
50 | } |
||
51 | |||
52 | foreach ($representations as $representation) { |
||
53 | if ($representation instanceof Representation) { |
||
54 | $filter[] = "-s:v"; |
||
55 | $filter[] = $representation->getResize(); |
||
56 | $filter[] = "-crf"; |
||
57 | $filter[] = "20"; |
||
58 | $filter[] = "-sc_threshold"; |
||
59 | $filter[] = "0"; |
||
60 | $filter[] = "-g"; |
||
61 | $filter[] = "48"; |
||
62 | $filter[] = "-keyint_min"; |
||
63 | $filter[] = "48"; |
||
64 | $filter[] = "-hls_list_size"; |
||
65 | $filter[] = "0"; |
||
66 | $filter[] = "-hls_time"; |
||
67 | $filter[] = $media->getHlsTime(); |
||
68 | $filter[] = "-hls_allow_cache"; |
||
69 | $filter[] = $media->isHlsAllowCache() ? "1" : "0"; |
||
70 | $filter[] = "-b:v"; |
||
71 | $filter[] = $representation->getKiloBitrate() . "k"; |
||
72 | $filter[] = "-maxrate"; |
||
73 | $filter[] = intval($representation->getKiloBitrate() * 1.2) . "k"; |
||
74 | $filter[] = "-hls_segment_filename"; |
||
75 | $filter[] = $dirname . "/" . $ts_sub_dir . $filename . "_" . $representation->getHeight() . "p_%04d.ts"; |
||
76 | |||
77 | if ($base_url) { |
||
78 | $filter[] = "-hls_base_url"; |
||
79 | $filter[] = $base_url; |
||
80 | } |
||
81 | |||
82 | if ($media->getHlsKeyInfoFile()) { |
||
83 | $filter[] = "-hls_key_info_file"; |
||
84 | $filter[] = $media->getHlsKeyInfoFile(); |
||
85 | } |
||
86 | |||
87 | $filter[] = "-strict"; |
||
88 | $filter[] = $media->getStrict(); |
||
89 | |||
90 | if (++$counter !== $total_count) { |
||
91 | $filter[] = $dirname . "/" . $filename . "_" . $representation->getHeight() . "p.m3u8"; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | return $filter; |
||
96 | } |
||
97 | } |