У меня есть служба, которая загружает файлы в определенном формате с сайта 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