Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

get_video_resolution()

Description

Get video resolution using FFMpeg

Parameters

ColumnTypeDefaultDescription
$file string Path to video file

Return

array

Location

include/video_functions.php lines 12 to 46

Definition

 
function get_video_resolution($file)
    {
    
$video_resolution = array(
        
'width'  => 0,
        
'height' => 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(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']);
                break;
                }
            }
        }

    return 
$video_resolution;
    }

This article was last updated 13th July 2020 15:35 Europe/London time based on the source file dated 24th June 2020 15:23 Europe/London time.