首页 > 解决方案 > 如何在 PHP 中代理 HLS m3u8

问题描述

我正在尝试代理 HLS 并更改用户代理,一切正常且没有错误,当访问 URL 时,文件将以 .m3u8 扩展名下载,但问题是无法播放,视频播放器不是问题,因为多次测试流正在工作。

这是我的代码

public function proxify($args = NULL) {
  $useragent = $this->request->get("ua");
  $url = $this->request->get("url");

  if($useragent != '' && $url != '') {

    $ch = curl_init();
    $headers = array(
    'User-Agent: ' . $useragent,
    );

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 

    $request = curl_exec($ch);

    header('Content-Type: video/mp2t');
    header('Content-Disposition: attachment; filename="' . basename($url) . '"');
    echo $request;

  } else {
    die('No URL Request found');
    exit();
  }

}

是什么问题,为什么不能播放?,检查网络选项卡的响应代码是 200

谢谢,赞赏

标签: phpproxyhttp-live-streamingm3u8

解决方案


推荐阅读