Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

get_video_resolution()

Description

Get video resolution and framerate using FFMpeg

Parameters

ColumnTypeDefaultDescription
$file string Path to video file

Return

array

Location

include/video_functions.php lines 12 to 62

Definition

 
function get_video_resolution($file)
    {
    
$video_resolution = array(
        
'width'     => 0,
        
'height'    => 0,
        
'framerate' => 0.0,
    );

    
$video_info get_video_info($file);

    
// Different versions of ffprobe store the dimensions in different parts of the json output
    
if(!empty($video_info['width']))
        {
        
$video_resolution['width'] = intval($video_info['width']);
        }

    if(!empty(
$video_info['height']))
        {
        
$video_resolution['height'] = intval($video_info['height']);
        }
    
    if (!empty(
$video_info['r_frame_rate'])) {
        
$framerate_pieces explode('/'$video_info['r_frame_rate']);

        if (
floatval($framerate_pieces[1]) > 0) {
            
$video_resolution['framerate'] = floatval($framerate_pieces[0] / $framerate_pieces[1]);    
        }
    }


    if(isset(
$video_info['streams']) && is_array($video_info['streams']))
        {
        foreach( 
$video_info['streams'] as $stream)
            {
            if(!empty(
$stream['codec_type']) && 'video' === $stream['codec_type'])
                {
                
$video_resolution['width']  = intval($stream['width']);
                
$video_resolution['height'] = intval($stream['height']);
                
                
$framerate_pieces explode('/'$stream['r_frame_rate']);
                if (
floatval($framerate_pieces[1]) > 0) {
                    
$video_resolution['framerate'] = floatval($framerate_pieces[0] / $framerate_pieces[1]);    
                }
                
                break;
                }
            }
        }

    return 
$video_resolution;
    }

This article was last updated 8th December 2024 09:35 Europe/London time based on the source file dated 10th September 2024 23:10 Europe/London time.