* Find the duration in seconds of a given video file. * * @param string $file A file path. * @return int|bool Either the duration or false. */
( $file )
| 288 | * @return int|bool Either the duration or false. |
| 289 | */ |
| 290 | function get_duration( $file ){ |
| 291 | $ffmpeg_output = shell_exec( "ffmpeg -i " . escapeshellarg( $file ) . " 2>&1" ); |
| 292 | |
| 293 | preg_match( "/Duration: (.{2}):(.{2}):(.{2})(?:\.([^,]+))?,/", $ffmpeg_output, $duration ); |
| 294 | |
| 295 | if ( ! isset( $duration[1] ) ) { |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | $hours = $duration[1]; |
| 300 | $minutes = $duration[2]; |
| 301 | $seconds = $duration[3]; |
| 302 | $decimal = $duration[4]; |
| 303 | |
| 304 | return floatval( ( $seconds + ( $minutes * 60 ) + ( $hours * 60 * 60 ) ) . "." . $decimal ); |
| 305 | } |
| 306 | |
| 307 | function add_base( $path ) { |
| 308 | global $base; |