How do you convert audio files (on the fly) to a browser?

I would like to be able to convert audio files to MP3 in a users browser on the fly. The software I use is Apache, PHP and FFMPEG on the ubuntu system. Here is the code that I still have:

<?php
     header("Content-Transfer-Encoding: binary");
     header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");

     passthru('ffmpeg -i song.flac -v 0 -ab 320k -f mp3 -');
?>

Only the first few seconds of audio are converted using this code, however, when I comment on the header functions, the audio file is completely converted, but all binary data is transferred to the screen (instead of being wrapped in the browsers of the mp3 player).

Any thoughts?

+3
source share
1 answer

, . ( ):

header("Content-Length: {$calculatedFileSize}"); 
+2

Source: https://habr.com/ru/post/1720806/


All Articles