Jump to content

Recommended Posts

Posted (edited)

I've written a little program to automatic converting videos from a folder in linux using ffmpeg via shell_exec in php easy enough to do and worthwhile for the thousands of little clips I have I've got it to start the conversion in another process so as not to stall the php script until it's completed. However once it is completed I want another command to run (again in a separate process) and update a record in mysql.

 

The & symbol works well but when you have two commands in shell_exec you use a ; to show a new command has started and putting an & in between doesn't work it fails to run the command and after is too late as the second command would run in a separate process but not the first so it would still delay the PHP script.

 

Any ideas on how I could do this?

 

shell_exec("ffmpeg input.avi output.mp4; php -e 'aphpfile.php'");

 

Any thoughts?

 

I know I should be using escapeshellarg but this is only used by me at the moment.

 

Wes

Edited by wesleyw
Posted

Haven't tried this yet but whilst searching for another way around this I found the following will work:

 

shell_exec("(ffmpeg input.avi output.mp4 && php -e 'aphpfile.php') > /dev/null 2> alogfile.log &");

 

The commands need to be encapsulated in parentheses and turning of stdin ">" and stderr "2>" to output to file also the & at the end will run it in a separate process.

 

So that looks like it has worked perfectly.

 

 

Wes

Posted

As the shell_exec would be running in another process they would complete asynchronously so the MySQL statement would change the status of a record before the conversion completes.

 

Wes

Posted (edited)
As the shell_exec would be running in another process they would complete asynchronously so the MySQL statement would change the status of a record before the conversion completes.

 

Wes

 

Sorry, I forgot about that!

 

You could just join the statements?

 


shell_exec([color=#800000]"[color=#333333][font=Verdana]ffmpeg input.avi output.mp4[/font][/color] > page.php 2>&1 &"[/color]);

Edited by SovietRussia

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...