1616use Streaming \Representation ;
1717use Streaming \Utiles ;
1818
19- class HLSFilter extends StreamFilter
19+ class HLSFilter extends FormatFilter
2020{
2121 /** @var \Streaming\HLS */
2222 private $ hls ;
@@ -36,17 +36,6 @@ class HLSFilter extends StreamFilter
3636 /** @var string */
3737 private $ seg_filename ;
3838
39- /**
40- * @return array
41- */
42- private function getFormats (): array
43- {
44- $ format = ['-c:v ' , $ this ->hls ->getFormat ()->getVideoCodec ()];
45- $ audio_format = $ this ->hls ->getFormat ()->getAudioCodec ();
46-
47- return $ audio_format ? array_merge ($ format , ['-c:a ' , $ audio_format ]) : $ format ;
48- }
49-
5039 /**
5140 * @param Representation $rep
5241 * @param bool $not_last
@@ -63,28 +52,28 @@ private function playlistPath(Representation $rep, bool $not_last): array
6352 */
6453 private function getAudioBitrate (Representation $ rep ): array
6554 {
66- return $ rep ->getAudioKiloBitrate () ? ["- b:a " , $ rep ->getAudioKiloBitrate () . "k " ] : [];
55+ return $ rep ->getAudioKiloBitrate () ? ["b:a " => $ rep ->getAudioKiloBitrate () . "k " ] : [];
6756 }
6857
6958 /**
7059 * @return array
7160 */
7261 private function getBaseURL (): array
7362 {
74- return $ this ->base_url ? ["- hls_base_url " , $ this ->base_url ] : [];
63+ return $ this ->base_url ? ["hls_base_url " => $ this ->base_url ] : [];
7564 }
7665
7766 private function flags (): array
7867 {
79- return !empty ($ this ->hls ->getFlags ()) ? ["- hls_flags " , implode ("+ " , $ this ->hls ->getFlags ())] : [];
68+ return !empty ($ this ->hls ->getFlags ()) ? ["hls_flags " => implode ("+ " , $ this ->hls ->getFlags ())] : [];
8069 }
8170
8271 /**
8372 * @return array
8473 */
8574 private function getKeyInfo (): array
8675 {
87- return $ this ->hls ->getHlsKeyInfoFile () ? ["- hls_key_info_file " , $ this ->hls ->getHlsKeyInfoFile ()] : [];
76+ return $ this ->hls ->getHlsKeyInfoFile () ? ["hls_key_info_file " => $ this ->hls ->getHlsKeyInfoFile ()] : [];
8877 }
8978
9079 /**
@@ -112,21 +101,22 @@ private function getSegmentFilename(Representation $rep): string
112101 */
113102 private function initArgs (Representation $ rep ): array
114103 {
115- return [
116- "-s:v " , $ rep ->size2string (),
117- "-crf " , "20 " ,
118- "-sc_threshold " , "0 " ,
119- "-g " , "48 " ,
120- "-keyint_min " , "48 " ,
121- "-hls_list_size " , $ this ->hls ->getHlsListSize (),
122- "-hls_time " , $ this ->hls ->getHlsTime (),
123- "-hls_allow_cache " , (int )$ this ->hls ->isHlsAllowCache (),
124- "-b:v " , $ rep ->getKiloBitrate () . "k " ,
125- "-maxrate " , intval ($ rep ->getKiloBitrate () * 1.2 ) . "k " ,
126- "-hls_segment_type " , $ this ->hls ->getHlsSegmentType (),
127- "-hls_fmp4_init_filename " , $ this ->getInitFilename ($ rep ),
128- "-hls_segment_filename " , $ this ->getSegmentFilename ($ rep )
104+ $ init = [
105+ "hls_list_size " => $ this ->hls ->getHlsListSize (),
106+ "hls_time " => $ this ->hls ->getHlsTime (),
107+ "hls_allow_cache " => (int )$ this ->hls ->isHlsAllowCache (),
108+ "hls_segment_type " => $ this ->hls ->getHlsSegmentType (),
109+ "hls_fmp4_init_filename " => $ this ->getInitFilename ($ rep ),
110+ "hls_segment_filename " => $ this ->getSegmentFilename ($ rep ),
111+ "s:v " => $ rep ->size2string (),
112+ "b:v " => $ rep ->getKiloBitrate () . "k "
129113 ];
114+
115+ return array_merge ($ init ,
116+ $ this ->getAudioBitrate ($ rep ),
117+ $ this ->getBaseURL (),
118+ $ this ->flags (),
119+ $ this ->getKeyInfo ());
130120 }
131121
132122 /**
@@ -137,12 +127,8 @@ private function getArgs(Representation $rep, bool $not_last): void
137127 {
138128 $ this ->filter = array_merge (
139129 $ this ->filter ,
140- $ this ->getFormats (),
141- $ this ->initArgs ($ rep ),
142- $ this ->getAudioBitrate ($ rep ),
143- $ this ->getBaseURL (),
144- $ this ->flags (),
145- $ this ->getKeyInfo (),
130+ $ this ->getFormatOptions ($ this ->hls ->getFormat ()),
131+ Utiles::arrayToFFmpegOpt ($ this ->initArgs ($ rep )),
146132 Utiles::arrayToFFmpegOpt ($ this ->hls ->getAdditionalParams ()),
147133 ["-strict " , $ this ->hls ->getStrict ()],
148134 $ this ->playlistPath ($ rep , $ not_last )
0 commit comments