声明:本文章只是指出部分网站的 BUG,希望有问题的网站尽快修复!请勿非法操作,出现任何问题与博主无关.
视频储存是很多人的一个难题...自己买个服务器又需要带宽有需要硬盘够大!
看看怎么是一个完美的存储.
开始操作
我也是偶然发现的。把视频切片成 m3u8 之后,视频会变成一段段的 ts 格式的视频。这个时候我想了一下。如果说某些图床又 bug 不验证文件格式,那么是不是就可以把切片视频放在他的服务器上进行播放了?
嘿嘿,没想到真的可以。当当当~ 他就是某里的“图床”。
有了方案我们就试试吧。
我直接上自动化脚本了:
- <?php
- $v_path = $argv[1]; //切片路径
- $v_name = $argv[2]; //带切片的视频路径名称
- $s = 5; //切片秒 ts 切片必须小于 5MB
- if (empty($v_path) || empty($v_name)) {
- echo "请填写完整参数";
- exit;
- }
- if ($v_path == '/' || $v_path == '\\') {
- $v_path = '';
- } else {
- mkFolder($v_path);
- $v_path = $v_path . "/";
- }
- //这是 FFmpeg 处理命令大家自行更改
- exec("ffmpeg -i $v_name -c copy -map 0 -f segment -segment_list " . $v_path . "playlist.m3u8 -segment_time $s " . $v_path . "player%03d.ts");
- $m = file_get_contents('./' . $v_path . 'playlist.m3u8');
- preg_match_all('/player(.*?)\.ts/', $m, $arr);
- foreach ($arr[1] as $key => $value) {
- echo "处理第" . $value . '个切片' . "\n";
- $ali = upload('./' . $v_path . 'player' . $value . '.ts');
- $m = str_replace('player' . $value . '.ts', $ali, $m);
- file_put_contents('./' . $v_path . 'play.m3u8', $m);
- }
- echo "处理完毕" . "\n";
- echo "播放链接为:/" . $v_path . 'play.m3u8';
- function upload($file) {
- $post['file'] = file_path($file);
- $post['scene'] = 'aeMessageCenterV2ImageRule';
- $post['name'] = 'player.jpg';
- $rel = get_curl('https://kfupload.alibaba.com/mupload', $post, 'iAliexpress/6.22.1 (iPhone; iOS 12.1.2; Scale/2.00)');
- $rel = json_decode($rel, true);
- return $rel['url'];
- }
- function get_curl($url, $post = 0, $ua = 0) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- // 不验证证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- // 最大执行时间
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
- curl_setopt($ch, CURLOPT_TIMEOUT, 120);
- $httpheader[] = "Accept:application/json";
- $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
- $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
- $httpheader[] = "Connection:close";
- $ip = mt_rand(48, 140) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240); //随机 ip
- $httpheader[] = 'CLIENT-IP:' . $ip;
- $httpheader[] = 'X-FORWARDED-FOR:' . $ip;
- curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
- if ($post) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- }
- if ($ua) {
- curl_setopt($ch, CURLOPT_USERAGENT, $ua);
- } else {
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
- }
- curl_setopt($ch, CURLOPT_ENCODING, "gzip");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $ret = curl_exec($ch);
- curl_close($ch);
- return $ret;
- }
- function mkFolder($path) {
- if (!is_readable($path)) {
- is_file($path) or mkdir($path, 0700);
- }
- }
- function file_path($file) {
- if (class_exists('CURLFile')) {
- return $post['file'] = new \CURLFile(realpath($file));
- } else {
- return $post['file'] = '@' . realpath($file);
- }
- }
把这个另存为 m3u8.php(什么名都成!这个就随便命名一下)
运行命令:
php m3u8.php 视频的储存路径 视频完整路径
如:
php m3u8.php mp4 wwwroot/test/test.mp4
注意:这个接口只能上次小于 5MB 以下的图片(视频切片)所以切片完文件大小必须小于 5MB,其他的自己看代码就能懂,其实没啥.
测试视频:

[x]
Player version
Player FPS
Video type
Video url
Video resolution
Video duration
Danamku id
Danamku api
Danamku amount
Danmaku load failed