【问题标题】:How to get the Lowest Quality YouTube video?如何获得最低质量的 YouTube 视频?
【发布时间】:2013-09-23 11:40:55
【问题描述】:

我有一个代码 sn-p 将 YouTube 视频转换为 .mp4 并将其存储在我的服务器中。它做的一切都是正确的,但它是一个高质量的视频版本,我的服务器基本上超时了。有没有办法可以检查视频是否不超过 20 MB 并获得最低质量的视频?

这是我的代码:

<?php
$id = $_GET['id'];
$format = 'video/mp4';
parse_str(file_get_contents("http://www.youtube.com/get_video_info?video_id=" . $id), $info);
$streams = $info['url_encoded_fmt_stream_map'];

$streams = explode(',', $streams);

foreach($streams as $stream) {
    parse_str($stream, $data);
    if(stripos($data['type'], $format) !== false) {
        $video = fopen($data['url'] . '&signature=' . $data['sig'], 'r');
        $file = fopen($_GET['id'] . '.mp4', 'w');
        stream_copy_to_stream($video, $file);
        fclose($video);
        fclose($file);
        echo '<a href="./' . $_GET['id'] . '.mp4">Download</a>';
        die();
    }
}
?>

【问题讨论】:

    标签: php video youtube youtube-api


    【解决方案1】:

    使用此代码,您可以获得资源的 Content-Length(大小):

    $url = "http://some-adress/test.php";
    $headers = get_headers($url, 1);
    $content_length = $headers["Content-Length"];
    

    如果您解析流图,则必须查找“itag”,即视频质量。 这是获取 itags 的 preg_match 示例:

    preg_match('/itag=([0-9]+)/',$url,$tm);
    

    这是所有代码及其含义的列表:

    $typeMap = 数组(); $typeMap[13] = array("13", "3GP", "低质量 - 176x144"); $typeMap[17] = array("17", "3GP", "中等质量 - 176x144"); $typeMap[36] = array("36", "3GP", "高质量 - 320x240"); $typeMap[5] = array("5", "FLV", "低质量 - 400x226"); $typeMap[6] = array("6", "FLV", "中等质量 - 640x360"); $typeMap[34] = array("34", "FLV", "中等质量 - 640x360"); $typeMap[35] = array("35", "FLV", "高质量 - 854x480"); $typeMap[120] = array("120", "FLV", "高质量 - 1280x720"); $typeMap[43] = array("43", "WEBM", "低质量 - 640x360"); $typeMap[44] = array("44", "WEBM", "中等质量 - 854x480"); $typeMap[45] = array("45", "WEBM", "高质量 - 1280x720"); $typeMap[18] = array("18", "MP4", "中等质量 - 480x360"); $typeMap[22] = array("22", "MP4", "高质量 - 1280x720"); $typeMap[37] = array("37", "MP4", "高质量 - 1920x1080"); $typeMap[38] = array("38", "MP4", "高质量 - 4096x230");

    来源:http://www.ngcoders.com/php-script/php-youtube-video-downloader-script/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2018-12-25
      • 2014-03-20
      • 2015-09-19
      相关资源
      最近更新 更多