PHP exec () does not work with ffmpeg

I am trying to run the following command in PHP (on Ubuntu):

<?php if (exec("/home/johnboy/ffmpeg/ffmpeg -i test1.mp4 -acodec aac -ab 128kb -vcodec mpeg4 -b 1220kb -mbd 1 -s 320x180 final_video.mov")) { echo "Success"; } else { echo "No good"; } 

And I always get a "Bad" response, and the file is not created.

Interestingly, if I run the exact same command in Shell, it works, no problem.

Also, when I run the same code above, but instead of "fmmpeg" instead of "fmmpeg", it replaces "whoami". (He repeats "Success")

Any ideas on why this will not work? Thanks.

+4
source share
8 answers

Can apache / web user reach /home/johnboy/ffmpeg/ffmpeg ? That is, perhaps /home/johnboy is 0700 instead of 0755?

Perhaps there are resource limitations affecting the loading of such a large program and all its libraries?

If you run the script in php cli sapi, then it behaves correctly? Even when working as an apache user?

What does strace -ff show when an apache website user runs a PHP script through php cli?

+2
source

get stderr will give the result

to try

 ffmpeg -i inputfile [more_params] 2>&1 
+4
source

Use this

 $ffmpeg = "ffmpeg Installed path"; $flvfile = "source video file with root path"; $png_path " "Destination video file with root path and file type"; exec("$ffmpeg -y -i $flvfile -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110x90 $png_path"); 
+2
source

There would be problems if you want to accomplish something.
1. Perhaps you have a permission problem, the web server has a limitation to handle some execution on the system.
2. Your path file may be incorrect.
3. You can try using shell_exec to execute the execution on the system.

In any case, what I would do to make my execution go smoothly. I will write 2 programs with messages sent between them, for example, a client server program. The server will wait for some messages from the client to execute any command (the whole command, this will not be a permission problem). All you need to do on the Internet is to call your client application.

What I emphasize is to create some interface from the Internet and the system. This will solve the permission problem.

hope this help.

+1
source

You use relative paths to file names. Are you sure you are executing the command in the correct directory?

0
source

The exec () function returns only the last line of output, I suspect that the last line of this command is empty. if you want the entire contents of the command to be used by shell_exec ().

Also track where the command is executed, try: print(shell_exec("pwd"));

0
source

Enable safe mode and it will work

0
source
 $output = shell_exec('/home/person/www/ffmpeg 2>&1'); echo "<pre>$output</pre>"; 

Pay attention to 2> & 1 part ...

0
source

Source: https://habr.com/ru/post/1303597/


All Articles