【发布时间】:2021-02-24 17:35:51
【问题描述】:
我有一项服务可以从网站remote.com/file.wav 下载特定格式的文件,并且必须像local.it/file.ogg 一样即时翻译它们。
这样做时,当有人访问local.com/file.mp4 时,站点会连接到remote.com/file.raw 下载文件,调用Windows 程序myconv.exe -i file.raw file.mp4 将其转换并提供file.ogg。
现在我有了下载脚本:
$file_to_download= str_replace('/','',$_SERVER['SCRIPT_NAME']);
$file_to_serve = str_replace('.raw','.mp4', $file_to_download); //actually this is the name the
// make a temporary filename that is unique
$name = 'c:\\tmp\\tmpfile'.str_shuffle("abcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZ1234567890");
//download the data
$data = file_get_contents('http://remote.com/'.$file_to_download,false);
//store the downloaded data on the disk
file_put_contents($name,$data);
//call the CLI utility
exec('start /B c:\\programs\\ffmpeg\\ffmpeg.exe -i'.$name.' '.$file_to_serve);
unlink($name)
//read the output file
$data = file_get_contents($file_to_serve);
$size = sizeof($data);
header("Content-Transfer-Encoding: binary");
header("Content-Type: ogg/vorbis);
header("Content-Length: $size");
unlink($file_to_serve);
echo $data;
我缺少的是如何告诉网络服务器(apache 或 IIS)“如果请求 ogg 文件,则调用此脚本”,而不是在文件系统中查找 .mp4 文件
【问题讨论】: