@@ -227,13 +227,28 @@ private static function getAudioTracks($pathFileName)
227227 private static function getScaledWidth ($ pathFileName , $ targetHeight )
228228 {
229229 $ command = get_ffprobe () . " -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0:s=x {$ pathFileName }" ;
230- $ output = shell_exec ($ command );
231- list ($ originalWidth , $ originalHeight ) = explode ('x ' , trim ($ output ));
230+ $ output = trim (shell_exec ($ command ));
232231
233- // Calculate proportional width based on the target height
234- $ width = intval (($ targetHeight / $ originalHeight ) * $ originalWidth );
232+ if (empty ($ output ) || strpos ($ output , 'x ' ) === false ) {
233+ _error_log ("FFprobe failed to get dimensions: output=[ $ output], using default 16:9 fallback " );
234+ return self ::getDefaultWidth ($ targetHeight );
235+ }
236+
237+ list ($ originalWidth , $ originalHeight ) = explode ('x ' , $ output );
238+
239+ if (empty ($ originalWidth ) || empty ($ originalHeight ) || $ originalHeight == 0 ) {
240+ _error_log ("Invalid dimensions received: width=[ $ originalWidth], height=[ $ originalHeight], using default 16:9 fallback " );
241+ return self ::getDefaultWidth ($ targetHeight );
242+ }
235243
236- // Round down to the nearest multiple of 2 (required by H.264 codec)
244+ $ width = intval (( $ targetHeight / $ originalHeight ) * $ originalWidth );
237245 return $ width - ($ width % 2 );
238246 }
247+
248+ private static function getDefaultWidth ($ targetHeight )
249+ {
250+ // 16:9 ratio → width = height * (16 / 9)
251+ $ width = intval ($ targetHeight * (16 / 9 ));
252+ return $ width - ($ width % 2 ); // ensure even number
253+ }
239254}
0 commit comments