I am trying to run a shell script in PHP through shell_exec(). The shell script merges two mp3 files using FFmpeg. I have tested the code in my terminal and it works just fine. However, I cannot get it to work with php. This is supposed to run when I click a button on a webpage (I am using WordPress). When I try doing this, it makes it to the shell script page, and makes it through it. But, it seems that FFmpeg does not work.
I call:
$new_file = realpath(dirname(__FILE__) . '/../../../scripts'). '/' . $new_file;
$path = realpath(dirname(__FILE__) . '/../../../scripts/combine-mp3.sh');
I get the $ad_file and $main_file from objects stored in a database.
$output = shell_exec('bash ' . $path . ' ' . $ad_file . ' ' . $main_file . ' ' . $new_file);
echo "<pre>$output</pre>";
Example of what it looks like:
bash
/Users/me/Documents/websites/zzz/wp-content/plugins/myplugin/scripts/combine-mp3.sh
http://localhost/zzz/wp-content/uploads/mp3/News_Intro.mp3
http://localhost/zzz/wp-content/uploads/mp3/main_file.mp3
new_file_test.mp3
The combine-mp3.sh then gets run:
#this script requires 3 files, input1, input2 and output
echo -e "Input File 1:\t" $1
echo -e "Input File 2:\t" $2
echo -e "Output File:\t" $3
#make sure there are not temporarily files floating around, they use long specific names to avoid accidentally removing important files
rm combine-mp3-temp-file-1.mp3
rm combine-mp3-temp-file-2.mp3
#create intermediate files at 128kbps
ffmpeg -i $1 -f mp3 -ab 128k -ar 44100 -ac 2 combine-mp3-temp-file-1.mp3
ffmpeg -i $2 -f mp3 -ab 128k -ar 44100 -ac 2 combine-mp3-temp-file-2.mp3
#combine the two intermediate files
ffmpeg -i "concat:combine-mp3-temp-file-1.mp3|combine-mp3-temp-file-2.mp3" -acodec copy $3
#remove temporary files now they are not needed
rm combine-mp3-temp-file-1.mp3
rm combine-mp3-temp-file-2.mp3
I am thinking it could possibly be the environment or something. But I have no idea what is wrong.