简体   繁体   中英

How to compress mp3 file in php

I am doing a php project. In my project, I need to compress mp3 files to reduce the file size because I need to store a lot of mp3 files.

How can I compress it in php? I am using laravel framework. If possible, I want it without extra installation. I already checked ffmpeg , but I was not able to use it due to the poor documentation. How can I achieve it?

Answer Already posted in the respective links of stackoverflow how-to-compress-or-convert-to-low-quality-mp3-file-from-php

While using zip command line with PHP to add a folder into an archive file:

General command:

zip archive.zip file.mp3

PHP code:

<?php $path2mp3 = '../Downloads/Medias/MP3/001.mp3';$site = 'site.com';$compressFolder = $site.'.zip';$cmd = "zip -r $compressFolder $path2mp3"; $compressMP3 = exec($cmd ." 2>&1" );echo $compressMP3;if($compressMP3){echo 'Done';}else{echo 'Not Done';}?>
    // Audio compress
    $inputAudio = public_path('/audio/myaudio.mp3');
    $outputAudio = public_path('/output/outputAudio.mp3');
    exec("ffmpeg -i $inputAudio -ab 64 $outputAudio");

    // Video compress
    $inputVideo = public_path('/audio/myvideo.mp4');
    $outputVideo = public_path('/output/outputVideo.mp4');
    exec("ffmpeg -i $inputVideo -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 $outputVideo");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM