如何在php中使用系统命令?

I am working on a PHP code as shown below in which conversion of mp4 into mp3 is happening at Line B.

I have added if block after system command to print Conversion Completed on the webpage once the conversion is complete but it doesn't seem to work.

Php code:

if (isset($_POST['id']))
{
    for($i=0; $i <count($mp4_files); $i++) {
        if($i == $_POST['id']) {
            $f = $mp4_files[$i];
            $parts = pathinfo($f); 
            switch ($parts['extension'])
            {  
            case 'mp4' :
                $filePath = $src_dir . DS . $f;

                print_r($f);  // Line A        

                system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result);  // Line B

                if($result)
                {
                    echo "Conversion Completed";
                }

            }
        }
    }
} 

Problem Statement:

I am wondering what changes I should make in the PHP code above so that once the conversion is complete; on the webpage, it should print Conversion Completed.

You can use shell_exec to get a return value and then put that in an if statement like this

$output = shell_exec('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3');
if ($output) {
   echo "Conversion Completed!";
   // or redirect here
}

Also, make sure to sanitize your inputs as they are exposed to a CLI interface.