仅供测试!!
环境配置 确保pclose popen shell_exec exec 等函数没被禁用
安装 ffmpeg
例如我在linux系列服务 /www/wwworoot 执行命令
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
xz -d ffmpeg-release-amd64-static.tar.xz
tar -xvf ffmpeg-release-amd64-static.tar
安装后 你的ffmpeg相对地址就是
'/www/wwwroot/ffmpeg-7.0.2-amd64-static/'
打开upload.php format-mp4-webm.php
把ffmpegpath,ffprobepath 地址替换成 对应地址
另外把upload.php中的 #$this->onvideo($uid, $conf); 的#去掉
本次测试转换位置为 upload.php
pclose(popen('php80 '.__DIR__.'/format-mp4-webm.php '.$tmpfile,'r'));
客户打开发帖界面 F12输入JS
let input = document.createElement('input');
input.type = 'file';
input.multiple = true;
input.onchange = async function () {
let p = new FormData();
p.set('video',this.files[0]);
return fetch('https://ai.acgi.moe/attach-create.htm',{
method:'POST',
headers:{
'content-action': 'attach/video',
'content-mime': this.files[0].type,
'content-width':999,
'ajax-fetch':1,
},
body:p
}).then(async response=>{
const reader = response.body.getReader();
while(true){
const {done,value} = await reader.read();
if(done)break;
console.log(new TextDecoder().decode(value));
}
});
};
input.click();
input.remove();
题外话 如何把所有文件转化为 MP4
if (in_array('mp4', $extarr)):
$extname = 'mp4';
elseif (in_array('webm', $extarr)):
$extname = 'webm';
else:
$extname = 'video';
endif;
把这里非MP4统一改成video 接着修改
$video->gif(\FFMpeg\Coordinate\TimeCode::fromSeconds(10), new \FFMpeg\Coordinate\Dimension(320, 240), 3)->save($tmpfile . '.gif');
move_uploaded_file($_FILES['video']['tmp_name'], $tmpfile . '.' . $extname);
下面添加条件当格式为video
if($extname=='video'):
pclose(popen('php80 '.__DIR__.'/format-to-mp4 '.$tmpfile,'r'));
endif;