MCPcopy Create free account
hub / github.com/cfinke/Channel-Two / get_duration

Function get_duration

parse-schedule.php:290–305  ·  view source on GitHub ↗

* 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 )

Source from the content-addressed store, hash-verified

288 * @return int|bool Either the duration or false.
289 */
290function 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
307function add_base( $path ) {
308 global $base;

Callers 1

index_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected