Current Location: Home> Latest Articles> PHP AMR to MP3 Conversion Tutorial: Convert Audio Format Easily with FFmpeg

PHP AMR to MP3 Conversion Tutorial: Convert Audio Format Easily with FFmpeg

M66 2025-10-16

PHP AMR to MP3 Conversion Tutorial

This tutorial explains how to use PHP together with FFmpeg to convert AMR audio files into MP3 format. With just a few steps, you can easily achieve audio format conversion — ideal for projects involving voice processing or audio uploads.

Preparation

Before writing the PHP code, make sure FFmpeg is installed on your server or local environment. You can check this by running the following command:

ffmpeg -version

If the command is not recognized, FFmpeg is not installed. Visit the official FFmpeg website to download and install it according to your operating system.

Writing the PHP Code

Next, let’s write the PHP code that uses the exec() function to call FFmpeg and perform the conversion. Here’s a complete example:

<?php
$amrFile = "input.amr";
$mp3File = "output.mp3";

$cmd = "ffmpeg -i $amrFile -acodec libmp3lame $mp3File";

exec($cmd);
?>

Explanation of the code:

  • $amrFile is the path to the input AMR file.
  • $mp3File is the path to the output MP3 file.
  • The exec() function executes the FFmpeg command to handle the audio format conversion.

Make sure your PHP environment has permission to run system commands, otherwise the conversion may fail.

Testing the Script

Save the above code as convert.php and place it on your server. Modify the $amrFile and $mp3File variables to match your actual file paths, then run the following command in your terminal:

php convert.php

Once executed successfully, you should find the converted MP3 file in the specified directory.

Conclusion

In this tutorial, you learned how to convert AMR files to MP3 format using PHP and FFmpeg. This approach is efficient and easy to integrate into audio upload systems, voice recognition platforms, or file management tools. FFmpeg is a powerful multimedia framework that supports numerous audio and video formats — you can explore further based on your project needs.

We hope this guide helps you successfully perform your conversions. Good luck!