Playing .m3u8 video using php curl

折月煮酒 提交于 2021-02-10 20:53:45

问题


I'm attempting to play a .m3u8 video using a php curl proxy. The following code seems to work, although it only returns the video #EXTM3U information but does not play the video.

Code:

<?php
//....proxy info
$auth = 'username:password'; 
$proxy_ip = '1.2.3.4.5'; 
$proxy_port = 8080; 
$path = $_GET['link'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $auth);
curl_exec($ch);
if (curl_error($ch)) {
    $error_msg = curl_error($ch);
    echo $error_msg;
}
curl_close($ch);
if (isset($error_msg)) {
    echo $error_msg;
}
?>

Output:

#EXTM3U #EXT-X-VERSION:3 #EXT-X-INDEPENDENT-SEGMENTS #EXT-X-STREAM-INF:BANDWIDTH=5640800,AVERAGE-BANDWIDTH=5640800,CODECS="avc1.4d4028,mp4a.40.2",RESOLUTION=1920x1080,FRAME-RATE=25.000 index4147.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=2421100,AVERAGE-BANDWIDTH=2421100,CODECS="avc1.4d401f,mp4a.40.2",RESOLUTION=1280x720,FRAME-RATE=25.000 index2073.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=1566400,AVERAGE-BANDWIDTH=1566400,CODECS="avc1.4d401f,mp4a.40.2",RESOLUTION=960x540,FRAME-RATE=25.000 index1296.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=1002100,AVERAGE-BANDWIDTH=1002100,CODECS="avc1.77.30,mp4a.40.2",RESOLUTION=746x420,FRAME-RATE=25.000 index783.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=774400,AVERAGE-BANDWIDTH=774400,CODECS="avc1.77.30,mp4a.40.2",RESOLUTION=640x360,FRAME-RATE=25.000 index576.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=421300,AVERAGE-BANDWIDTH=421300,CODECS="avc1.42c015,mp4a.40.2",RESOLUTION=426x240,FRAME-RATE=25.000 index255.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=476300,AVERAGE-BANDWIDTH=476300,CODECS="avc1.42c01f,mp4a.40.2",RESOLUTION=640x360,FRAME-RATE=25.000 index101.m3u8

Any ideas regarding how I can play the video?

来源:https://stackoverflow.com/questions/52203064/playing-m3u8-video-using-php-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!