77class Metadata extends TranscodingTask {
88 function __construct ($ api , $ task_token )
99 {
10- // вызов конструктора базового класс
1110 parent ::__construct ($ api , $ task_token );
1211 }
1312 /**
@@ -25,9 +24,6 @@ public function get(string $video_url) {
2524 do {
2625 sleep (5 );
2726 $ response =parent ::getStatus ();
28- if (is_array ($ response ) and array_key_exists ('percent ' , $ response )) {
29- log_message ("Completed: {$ response ['percent ' ]}% " );
30- }
3127 } while ($ response ['status ' ] != 'completed ' );
3228
3329 $ urlMet = '' ;
@@ -37,4 +33,66 @@ public function get(string $video_url) {
3733 $ response = $ this ->api ->get ($ urlMet );
3834 return $ response ;
3935 }
36+
37+ public static function get_a_stream_by_codec_type ($ video_info , $ codec_type ) {
38+ if (! array_key_exists ('streams ' , $ video_info )) {
39+ return null ;
40+ }
41+ foreach ($ video_info ['streams ' ] as $ stream ) {
42+ if ($ stream ['codec_type ' ] == $ codec_type ) {
43+ return $ stream ;
44+ }
45+ }
46+ return null ;
47+ }
48+
49+ public static function get_video_stream_info ($ video_info ) {
50+ return self ::get_a_stream_by_codec_type ($ video_info , 'video ' );
51+ }
52+
53+ public static function get_audio_stream_info ($ video_info ) {
54+ return self ::get_a_stream_by_codec_type ($ video_info , 'audio ' );
55+ }
56+
57+ public static function get_video_dimensions ($ video_info ) {
58+ $ video_stream = self ::get_video_stream_info ($ video_info );
59+ if (! $ video_stream )
60+ return null ;
61+ return [$ video_stream ['width ' ], $ video_stream ['height ' ]];
62+ }
63+
64+ public static function get_bitrate ($ video_info , $ stream_type = 'video ' ) {
65+ $ stream = null ;
66+ if ($ stream_type == 'video ' ) {
67+ $ stream = self ::get_video_stream_info ($ video_info );
68+ }
69+ if ($ stream_type == 'audio ' ) {
70+ $ stream = self ::get_audio_stream_info ($ video_info );
71+ }
72+ if (is_array ($ stream ) and array_key_exists ('bit_rate ' , $ stream )) {
73+ $ bitrate = $ stream ['bit_rate ' ];
74+ }
75+ else {
76+ $ bitrate = null ;
77+ }
78+ return $ bitrate ;
79+ }
80+
81+ public static function get_framerate ($ video_info ) {
82+ $ stream = self ::get_video_stream_info ($ video_info );
83+ $ avg_frame_rate = $ stream ['avg_frame_rate ' ];
84+ if (strpos ($ avg_frame_rate , '/ ' ) !== FALSE ) {
85+ $ buf = explode ('/ ' , $ avg_frame_rate );
86+ $ framerate = floatval ($ buf [0 ]) / floatval ($ buf [1 ]);
87+ }
88+ else {
89+ $ framerate = floatval ($ avg_frame_rate );
90+ }
91+ return round ($ framerate , 2 );
92+ }
93+
94+ public static function get_duration ($ video_info ) {
95+ return $ video_info ['format ' ]['duration ' ];
96+ }
97+
4098}
0 commit comments