exec() command not working - php

I am using exec() function to run my commands on centos server. All was working fine untill i used command:
$command=
ffmpeg -i input video.mp4 -vf fade=out:0:5 output.mp4
The command is ok as it is running on server via command line but when i execute it using php it is not giving the output. I have already created a video from ffmpeg using the exec() function but this command is not working. What can be the reason i am confused how a command can run on server but not work while executing from php.
Other command i executed using exec() function is :
$command = ffmpeg -i %d.jpg -y -s 320x240 -aspect 4:3 output.mp4
and it is working perfectly and the video is also created but previous command is not giving video as output.
Please guide me...

Try debugging you command execution. For ffmpeg you need to pipe the output with 2>&1 to see it:
exec($command." 2>&1", $output);
echo "<pre>";
var_dump($output);
echo "</pre>";

Related

how can i run ffmpeg command in background php

Hello guys i am building a web app with php, i want to add watermark to a video with ffmpeg but due the process do take time to finish, i want to run it in the background, here is the command that i used
$hidey=" 2>/dev/null >/dev/null &";
$cmd="ffmpeg -i $video_name -i watermark.jpg -filter_complex overlay=W-w-5:H-h-15[video];[video]drawtext=\"text=$text:fontcolor=white:fontsize=10:x=(w-text_w)-5: y=(h-text_h)-5\" $new_file
$hidey";
shell_exec("$cmd")
the above command does not work, i dont know why, what did i do wrong
I also tried var_dump(shell_exec("$cmd")), so that i can get the error, it gave me NULL

ffmpeg showing null when i am trying using php file

Here is the output ffmpeg path in server
root#server.rkv.igq.mybluehost.me [~]# whereis ffmpeg
ffmpeg: /usr/bin/ffmpeg /usr/local/bin/ffmpeg /usr/include/ffmpeg /usr/share/ffm peg /usr/share/man/man1/ffmpeg.1.gz /usr/src/ffmpegscript/ffmpeg
When I am trying to run command (ffmpeg -i sample.mp4 sample.avi) using SSH it is working fine but when I am trying using PHP it is not working. Here is my PHP code:
include 'usr/local/bin/ffmpeg/';
var_dump(shell_exec('ffmpeg -i sample.mp4 sample.avi'));
Can you try with simple command like :
<?php
echo "Starting ffmpeg...\n\n";
echo shell_exec("ffmpeg -i input.avi output.avi &");
echo "Done.\n";
?>
If that does not work I think you should try this: https://github.com/PHP-FFMpeg/PHP-FFMpeg requires ffmpeg installd + ffprobe.

ffmpeg is working in terminal but not in php

I have installed ffmpeg using Ubuntu,
sudo apt-get install ffmpeg
ffmpeg is installed on root "/usr/bin/ffmpeg".
It's working fine in the terminal, but when I execute that using php i don't get any output.
shell_exec(/usr/bin/ffmpeg -y -i ./upload/1535531595first.mp3 -i ./upload/1535531595second.mp3 -filter_complex "[0:0][1:0] amix=inputs=2:duration=longest" -c:a libmp3lame ./download/1535531595outputnow1.mp3)
and using this command in "opt/lampp/htdocs/project-Name/sub-directory/test.php" file.
Any help will be appreciatable. Thanks in Advance. find the attachment cmd terminal working fine but for php not working
It works everywhere perfectly! I'm using FFMPEG with my PHP project too, The most common problems are:
Not using double quotation mark (").
Wrong addressing.
First of all, check your path, It's better to address your file from the root directory like this /user/foo/bar.mp3 and do the same thing for your output.
$input_file = "/user/foo/bar.mp3";
$output_file = "/user/foo/out.mp3";
shell_exec("ffmpeg -i \"{$input_file}\" \"{$output_file}\");
By the way, There is an issue with the web applications When you are using FFMPEG in your PHP project you may get the timeout error because it takes too much time to process.
I'd suggest you use this following script, It executes command-line commands in the background process
function Execute($CMD)
{
$OS = strtoupper(PHP_OS_FAMILY);
if ($OS == 'WINDOWS') {
return pclose(popen("start /B {$CMD}", "r"));
} else {
return shell_exec("{$CMD} > /dev/null 2>/dev/null &");
}
}

FFMPEG works from command line but not PHP

I have a strange situation that has just happend. FFMPEG is no longer executing from PHP but will from the command line.
Here is exactly what the command is:
ffmpeg -i ../../uploads/ee78d5deb564901626067cc0008456ed.mp3 -ab 96k -y ../../uploads/mp3/ee78d5deb564901626067cc0008456ed_6203688.mp3
How it is executed in the PHP script:
if(! exec("ffmpeg -i ".$target_path."".$hash_filename.".".$path_extension." -ab 96k -y ".$target_path."mp3/".$hash_filename."_".$session_ID.".mp3")){
echo 'ffmpeg failed';
}
This command did work but not longer does. I have recently updated plesk but I highly doubt that has affected this. The only thing that I think could affect it that I have recently done is have the file upload go to a subdomain. So the directory where the file is located and stored in the command is in a directory outside the document root. However, the move_uploaded_file function works and I have altered the open_basedir in PHP ini to the webspace root.
tail -f /var/log/apache2/error_log
and lets us know what you see there...Adjust for your platform...
this is for lamp (opensuse )
You can try the system() command. It will return you the response from server
system("ffmpeg -i ".$target_path."".$hash_filename.".".$path_extension." -ab 96k -y ".$target_path."mp3/".$hash_filename."_".$session_ID.".mp3")
if the ffmpeg is not supported with current version of the php it will return you the error.
OR
you can modify your command to get ffmpeg with proper path. In my case it works like below code
exec("/usr/local/bin/ffmpeg -i ".$target_path."".$hash_filename.".".$path_extension." -ab 96k -y ".$target_path."mp3/".$hash_filename."_".$session_ID.".mp3"))

PHP's exec() not executing command for FFmpeg

I have installed ffmpeg on my server and it works fine via my terminal. I'm able to successfully convert a file to webm format, so I'm sure the installation is fine. I'm also sure that I only have one installation of ffmpeg installed on my machine.
A problem arises when I try to convert files through PHP via PHP's exec(). When I run the same commands, I ran in the terminal, nothing happens. I looked around stackoverflow and other parts of the net for some help. I tried this to see the output:
exec($cmd, $out, $rv);
echo "output is:\n".implode("\n", $out)."\n exit code:$rv\n";
The output is: "output is: exit code:127"
The command I'm using is in this format:
ffmpeg -i "sample.mov" -vcodec libvpx -r 30 -b "644k" -acodec libvorbis -ab 128000 -ar "44100" -ac 2 -s "352x198" "sample.webm"
I've tried replacing "ffmpeg" with the full path to FFmpeg but that did not work.
Why isn't the script running the command correctly and converting the files?
Thank you!
Error code 127 means the executable (ffmpeg) couldn't be found. Try specifying the whole path (you can that out find in your terminal with which ffmpeg) or compare the value of the PATH environment variable in your php script and terminal.
I have similar problem with ant target executions from php. I can't get whole output from ant command only first few rows and ant target was not executed. In other words is partial executed.
With bellow command I've managed to run it but output of the command is append to log_file.log.
$commandString = 'you_command_here >> log_file.log 2>&1 &';
$command = exec($commandString);
Hope this will work for you.

Categories