用于视频质量选择器的PHP条件语句未显示结果

时间:2018-01-26 19:41:08

标签: php

我正在尝试从ffprobe生成可能的视频质量,但它没有使用条件语句IF-ELSE选择正确的结果。我确定这些可能品质的策略可能是错误的,但在对它进行了长时间的研究之后。我无法完成目标,我只是通过将视频的heightwidth相乘,然后手动将视频质量放在array()中,但我的代码没有选择对了。

这是我为它写的代码

exec("ffprobe -i josh.mp4 -v quiet -print_format json -show_format -show_streams -hide_banner > temp_file", $output, $res);
$info = json_decode(file_get_contents("temp_file"));
    echo "Video duration: " . $info->format->duration . "\n<br>";
    echo "Video size: " . $info->format->size . "\n<br>";
    echo "Video resolution width: " . $info->streams[0]->width . "\n<br>";
    echo "Video resolution height: " . $info->streams[0]->height . "\n<br>";
    echo "Video aspect ratio: " . $info->streams[0]->display_aspect_ratio . "\n<br>";
    echo "Video codec: " . $info->streams[0]->codec_name . "\n<br>";
    echo "Audio codec: " . $info->streams[1]->codec_name . "\n<br>";
    echo "Audio sample rate: " . $info->streams[1]->sample_rate . "\n<br>";
$video_converstions = null;
$video_resolution = $info->streams[0]->width*$info->streams[0]->height;

if ($video_resolution > '921600' || $video_resolution < '2073600') { // 1080p
    $video_converstions = array('144', '240', '360', '480', '720', '1080');

} elseif ($video_resolution > '409920' || $video_resolution < '921600') { // 720p
    $video_converstions = array('144', '240', '360', '480', '720');

} elseif ($video_resolution > '230400' || $video_resolution < '409920') { // 480p
    $video_converstions = array('144', '240', '360', '480');

} elseif ($video_resolution > '102240' || $video_resolution < '230400') { // 360p
    $video_converstions = array('144', '240', '360');

} elseif ($video_resolution > '36864' || $video_resolution < '102240') { // 240p
    $video_converstions = array('144', '240');

} elseif ($video_resolution > '0' && $video_resolution < '36864') { // 144p
    $video_converstions = array('144');
} else { // 144p
    $video_converstions = array('144');
}

echo "<pre>";
print_r($video_converstions);
echo "</pre>";

以下是我能够打印的结果

Video duration: 10.640000
Video size: 527821
Video resolution width: 400
Video resolution height: 300
Video aspect ratio: 0:1
Video codec: h264
Audio codec: aac
Audio sample rate: 48000

Array (
    [0] => 144
    [1] => 240
    [2] => 360
    [3] => 480
    [4] => 720
    [5] => 1080
)

我的期望是我使用的条件语句将仅打印360p的结果,但它根本不起作用。如果任何其他简单的解决方案可以取代我的策略,那将是非常愉快

2 个答案:

答案 0 :(得分:1)

需要将'或'切换为'和'

$video_converstions = null;
$video_resolution = 400*300;

if ($video_resolution > '921600' and $video_resolution < '2073600') { // 1080p
  $video_converstions = array('144', '240', '360', '480', '720', '1080');

} elseif ($video_resolution > '409920' and $video_resolution < '921600') { // 720p
  $video_converstions = array('144', '240', '360', '480', '720');

} elseif ($video_resolution > '230400' and $video_resolution < '409920') { // 480p
  $video_converstions = array('144', '240', '360', '480');

} elseif ($video_resolution > '102240' and $video_resolution < '230400') { // 360p
  $video_converstions = array('144', '240', '360');

} elseif ($video_resolution > '36864' and $video_resolution < '102240') { // 240p
  $video_converstions = array('144', '240');

} elseif ($video_resolution > '0' and $video_resolution < '36864') { // 144p
  $video_converstions = array('144');

} else { // 144p
  $video_converstions = array('144');
}   


echo($video_resolution.'<br>');
print_r($video_converstions);

答案 1 :(得分:0)

基于像素的精度不是100%,您应该建立自己的数据库

function quality ($in) {
    $wh = array(
        '3840x2160' => '1080p',
        '2560x1440' => '1080p',
        '1920x1080' => '1080p',
        '1918x1080' => '1080p',
        '1920x1078' => '1080p',
        '1916x1080' => '1080p',
        '1914x1080' => '1080p',
        '1920x1076' => '1080p',
        '1912x1080' => '1080p',
        '1906x1080' => '1080p',
        '1920x1072' => '1080p',
        '1904x1080' => '1080p',
        '1896x1080' => '1080p',
        '1920x1064' => '1080p',
        '1920x1056' => '1080p',
        '1872x1080' => '1080p',
        '1920x1048' => '1080p',
        '1862x1080' => '1080p',
        '1860x1080' => '1080p',
        '1850x1080' => '1080p',
        '1920x1040' => '1080p',
        '1916x1040' => '1080p',
        '1920x1036' => '1080p',
        '1920x1034' => '1080p',
        '1920x1032' => '1080p',
        '1920x1030' => '1080p',
        '1826x1080' => '1080p',
        '1920x1024' => '1080p',
        '1920x1020' => '1080p',
        '1808x1080' => '1080p',
        '1920x1016' => '1080p',
        '1800x1080' => '1080p',
        '1920x1012' => '1080p',
        '1792x1080' => '1080p',
        '1776x1080' => '1080p',
        '1920x960' => '1080p',
        '1920x956' => '1080p',
        '1920x952' => '1080p',
        '1960x868' => '1080p',
        '1920x874' => '1080p',
        '1920x872' => '1080p',
        '1920x856' => '1080p',
        '1488x1080' => '1080p',
        '1472x1080' => '1080p',
        '1920x824' => '1080p',
        '1464x1080' => '1080p',
        '1920x816' => '1080p',
        '1920x812' => '1080p',
        '1920x810' => '1080p',
        '1440x1080' => '1080p',
        '1438x1080' => '1080p',
        '1920x808' => '1080p',
        '1436x1080' => '1080p',
        '1920x806' => '1080p',
        '1920x804' => '1080p',
        '1920x802' => '1080p',
        '1920x800' => '1080p',
        '1920x798' => '1080p',
        '1920x796' => '1080p',
        '1920x792' => '1080p',
        '1408x1080' => '1080p',
        '1920x784' => '1080p',
        '1920x768' => '1080p',
        '1920x764' => '1080p',
        '1920x720' => '1080p',
        '1920x696' => '1080p',
        '816x1080' => '1080p',
        '1282x528' => '1080p',

        '1916x1076' => '720p',
        '1914x1076' => '720p',
        '1912x1076' => '720p',
        '1912x1072' => '720p',
        '1918x1040' => '720p',
        '1916x1038' => '720p',
        '1916x1034' => '720p',
        '1912x1036' => '720p',
        '1916x1032' => '720p',
        '1904x1024' => '720p',
        '1680x1050' => '720p',
        '1916x816' => '720p',
        '1912x808' => '720p',
        '1916x804' => '720p',
        '1428x1078' => '720p',
        '1918x802' => '720p',
        '1916x800' => '720p',
        '1912x800' => '720p',
        '1912x798' => '720p',
        '1916x796' => '720p',
        '1424x1068' => '720p',
        '1916x792' => '720p',
        '1912x792' => '720p',
        '1908x792' => '720p',
        '1908x788' => '720p',
        '1904x784' => '720p',
        '1392x1040' => '720p',
        '1920x720' => '720p',
        '1736x720' => '720p',
        '1720x720' => '720p',
        '1712x720' => '720p',
        '1664x720' => '720p',
        '1280x720' => '720p',
        '1278x720' => '720p',
        '1280x718' => '720p',
        '1280x716' => '720p',
        '1272x720' => '720p',
        '1280x714' => '720p',
        '1280x704' => '720p',
        '1248x720' => '720p',
        '1280x696' => '720p',
        '1280x694' => '720p',
        '1280x692' => '720p',
        '1280x688' => '720p',
        '1280x686' => '720p',
        '1280x682' => '720p',
        '1206x720' => '720p',
        '1204x720' => '720p',
        '1200x720' => '720p',
        '1280x674' => '720p',
        '1280x672' => '720p',
        '1280x668' => '720p',
        '1184x720' => '720p',
        '1172x720' => '720p',
        '1280x640' => '720p',
        '1280x638' => '720p',
        '1280x634' => '720p',
        '1280x628' => '720p',
        '1280x626' => '720p',
        '1280x600' => '720p',
        '1280x598' => '720p',
        '1280x596' => '720p',
        '1280x582' => '720p',
        '1280x576' => '720p',
        '994x720' => '720p',
        '992x720' => '720p',
        '1280x550' => '720p',
        '1280x546' => '720p',
        '1280x544' => '720p',
        '1278x544' => '720p',
        '1280x542' => '720p',
        '1280x540' => '720p',
        '960x720' => '720p',
        '958x720' => '720p',
        '1280x538' => '720p',
        '1280x536' => '720p',
        '1280x534' => '720p',
        '1280x532' => '720p',
        '1280x530' => '720p',
        '940x720' => '720p',
        '1280x528' => '720p',
        '1280x502' => '720p',
        '1280x496' => '720p',
        '864x720' => '720p',
        '1146x480' => '720p',
        '800x448' => '720p',
        '800x432' => '720p',
        '404x720' => '720p',

        '1152x648' => '480p',
        '1274x544' => '480p',
        '1276x532' => '480p',
        '1270x532' => '480p',
        '1264x528' => '480p',
        '1088x608' => '480p',
        '1024x576' => '480p',
        '864x648' => '480p',
        '992x558' => '480p',
        '1140x480' => '480p',
        '960x540' => '480p',
        '960x538' => '480p',
        '960x514' => '480p',
        '1008x480' => '480p',
        '920x518' => '480p',
        '896x504' => '480p',
        '1020x440' => '480p',
        '854x520' => '480p',
        '768x576' => '480p',
        '960x456' => '480p',
        '864x490' => '480p',
        '864x486' => '480p',
        '864x480' => '480p',
        '720x576' => '480p',
        '856x480' => '480p',
        '854x480' => '480p',
        '752x544' => '480p',
        '852x480' => '480p',
        '854x478' => '480p',
        '850x480' => '480p',
        '848x480' => '480p',
        '854x476' => '480p',
        '854x474' => '480p',
        '854x468' => '480p',
        '854x464' => '480p',
        '694x570' => '480p',
        '720x544' => '480p',
        '812x480' => '480p',
        '854x456' => '480p',
        '720x540' => '480p',
        '854x454' => '480p',
        '804x480' => '480p',
        '720x528' => '480p',
        '768x480' => '480p',
        '688x528' => '480p',
        '688x512' => '480p',
        '726x480' => '480p',
        '720x480' => '480p',
        '854x382' => '480p',
        '664x480' => '480p',
        '656x480' => '480p',
        '654x480' => '480p',
        '640x490' => '480p',
        '640x488' => '480p',
        '640x486' => '480p',
        '648x480' => '480p',
        '640x484' => '480p',
        '854x362' => '480p',
        '644x480' => '480p',
        '854x360' => '480p',
        '640x480' => '480p',
        '640x478' => '480p',
        '634x480' => '480p',
        '854x356' => '480p',
        '854x354' => '480p',
        '854x352' => '480p',
        '626x480' => '480p',
        '624x480' => '480p',
        '854x320' => '480p',
        '480x360' => '480p',
        '320x512' => '480p',

        '848x478' => '360p',
        '800x450' => '360p',
        '800x436' => '360p',
        '780x440' => '360p',
        '852x394' => '360p',
        '768x432' => '360p',
        '852x370' => '360p',
        '746x420' => '360p',
        '848x360' => '360p',
        '640x476' => '360p',
        '640x472' => '360p',
        '704x428' => '360p',
        '718x410' => '360p',
        '720x408' => '360p',
        '720x406' => '360p',
        '720x404' => '360p',
        '718x404' => '360p',
        '720x400' => '360p',
        '706x404' => '360p',
        '706x402' => '360p',
        '720x392' => '360p',
        '704x400' => '360p',
        '720x390' => '360p',
        '720x388' => '360p',
        '712x392' => '360p',
        '704x396' => '360p',
        '720x384' => '360p',
        '800x338' => '360p',
        '704x384' => '360p',
        '592x448' => '360p',
        '720x368' => '360p',
        '720x364' => '360p',
        '720x360' => '360p',
        '672x384' => '360p',
        '576x432' => '360p',
        '720x342' => '360p',
        '688x352' => '360p',
        '720x334' => '360p',
        '576x416' => '360p',
        '720x328' => '360p',
        '654x360' => '360p',
        '648x360' => '360p',
        '650x358' => '360p',
        '672x346' => '360p',
        '648x358' => '360p',
        '644x360' => '360p',
        '640x362' => '360p',
        '642x360' => '360p',
        '640x360' => '360p',
        '638x360' => '360p',
        '640x358' => '360p',
        '636x360' => '360p',
        '630x360' => '360p',
        '720x314' => '360p',
        '626x360' => '360p',
        '640x352' => '360p',
        '720x312' => '360p',
        '634x352' => '360p',
        '720x308' => '360p',
        '640x346' => '360p',
        '632x350' => '360p',
        '720x306' => '360p',
        '640x344' => '360p',
        '624x352' => '360p',
        '720x304' => '360p',
        '640x342' => '360p',
        '720x302' => '360p',
        '602x360' => '360p',
        '600x360' => '360p',
        '720x300' => '360p',
        '640x336' => '360p',
        '640x334' => '360p',
        '720x294' => '360p',
        '720x288' => '360p',
        '606x340' => '360p',
        '512x400' => '360p',
        '640x320' => '360p',
        '624x328' => '360p',
        '640x318' => '360p',
        '564x360' => '360p',
        '512x384' => '360p',
        '512x380' => '360p',
        '672x288' => '360p',
        '592x320' => '360p',
        '576x320' => '360p',
        '560x320' => '360p',
        '480x368' => '360p',
        '640x274' => '360p',
        '576x304' => '360p',
        '640x272' => '360p',
        '640x270' => '360p',
        '640x268' => '360p',
        '640x266' => '360p',
        '548x304' => '360p',
        '624x256' => '360p',
        '640x248' => '360p',
        '608x256' => '360p',
        '528x294' => '360p',
        '526x294' => '360p',
        '592x256' => '360p',
        '448x336' => '360p',
        '512x288' => '360p',
        '504x278' => '360p',
        '432x320' => '360p',
        '480x288' => '360p',
        '416x320' => '360p',
        '480x276' => '360p',
        '480x272' => '360p',
        '480x270' => '360p',
        '480x268' => '360p',
        '480x256' => '360p',
        '400x304' => '360p',
        '480x240' => '360p',
        '384x288' => '360p',
        '426x240' => '360p',
        '368x272' => '360p',
        '416x240' => '360p',
        '352x264' => '360p',
        '400x226' => '360p',
        '426x178' => '360p',
        '352x180' => '360p',
        '320x176' => '360p',
        '256x138' => '360p',
    );
    if(!isset($wh[$in])){
        $out = 'Unknown';
    }else{
        $out = $wh[$in];
    }
    return $out;
}