PHP、golang 如何播放mp4文件

php的处理过程

<?php
function PutMovie(file) {
    header("Content-type: video/mp4");
    header("Accept-Ranges: bytes");size = filesize(file);
    if(isset(_SERVER['HTTP_RANGE'])){
        header("HTTP/1.1 206 Partial Content");
        list(name,range) = explode("=", _SERVER['HTTP_RANGE']);
        list(begin, end) =explode("-",range);
        if(end == 0)end = size - 1;
    }
    else {begin = 0; end =size - 1;
    }
    header("Content-Length: " . (end -begin + 1));
    header("Content-Disposition: filename=".basename(file));
    header("Content-Range: bytes ".begin."-".end."/".size);
 
    fp = fopen(file, 'rb');
    fseek(fp,begin);
    while(!feof(fp)) {p = min(1024, end -begin + 1);
        begin +=p;
        echo fread(fp,p);
    }
    fclose($fp);
}
PutMovie("1.mp4");

golang的处理过程

http.ServeFile(w, r, "/webserver/1.mp4")

 

打赏
Bookmark the permalink.
0 0 投票数
文章评分
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论