S
S
skijaev2020-06-30 23:01:54
PHP
skijaev, 2020-06-30 23:01:54

How to use ffmpeg to convert an mp3 file to wav format before downloading by the user in PHP without having to create a wav file on the server?

I have a database of mp3 files. For example file s1.mp3
The user needs to download this file in wav format.
I can convert the file like this And give the received file like this
exec ("ffmpeg -i s1.mp3 s1.wav",$output);

header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=' . basename($file));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            readfile($file);

But after that you will have to delete the s1.wav file. Therefore, this method does not suit me.
Is it possible to somehow immediately organize the conversion using ffmpeg without creating a file, but immediately to download it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-06-30
@skijaev

In any case, first save, then delete. Either immediately after the return to the client, or by krone. After all, the client may not immediately download the entire file. Internet will be interrupted, for example)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question