+ Post New Thread
Results 1 to 6 of 6
Web Development Thread, PHP FFMPEG in Coding and Web Development; I've written a little program to automatic converting videos from a folder in linux using ffmpeg via shell_exec in php ...
  1. #1
    wesleyw's Avatar
    Join Date
    Dec 2005
    Location
    Kingswinford
    Posts
    2,202
    Thank Post
    223
    Thanked 50 Times in 44 Posts
    Blog Entries
    1
    Rep Power
    29

    PHP FFMPEG

    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
    Last edited by wesleyw; 27th September 2013 at 09:57 AM.

  2. #2
    penfold_99's Avatar
    Join Date
    Feb 2008
    Location
    East Sussex
    Posts
    896
    Thank Post
    54
    Thanked 152 Times in 105 Posts
    Rep Power
    65
    When I have run two programs from the command line I have used &&

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

  3. Thanks to penfold_99 from:

    wesleyw (27th September 2013)

  4. #3
    wesleyw's Avatar
    Join Date
    Dec 2005
    Location
    Kingswinford
    Posts
    2,202
    Thank Post
    223
    Thanked 50 Times in 44 Posts
    Blog Entries
    1
    Rep Power
    29
    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

  5. #4
    SovietRussia's Avatar
    Join Date
    Mar 2013
    Posts
    552
    Thank Post
    55
    Thanked 111 Times in 88 Posts
    Rep Power
    39
    Or just run a mysql_query after the shell_exec code?

  6. #5
    wesleyw's Avatar
    Join Date
    Dec 2005
    Location
    Kingswinford
    Posts
    2,202
    Thank Post
    223
    Thanked 50 Times in 44 Posts
    Blog Entries
    1
    Rep Power
    29
    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

  7. #6
    SovietRussia's Avatar
    Join Date
    Mar 2013
    Posts
    552
    Thank Post
    55
    Thanked 111 Times in 88 Posts
    Rep Power
    39
    Quote Originally Posted by wesleyw View Post
    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?

    Code:
    shell_exec("ffmpeg input.avi output.mp4 > page.php 2>&1 &");
    Last edited by SovietRussia; 27th September 2013 at 02:00 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. [PHP] PHP Server Monitor
    By zag in forum Web Development
    Replies: 40
    Last Post: 22nd May 2013, 12:05 PM
  2. [PHP] PHP Data Grid
    By monkeyx in forum Web Development
    Replies: 0
    Last Post: 6th October 2009, 10:35 AM
  3. [PHP] MRBS config.inc.php
    By adminray in forum Web Development
    Replies: 3
    Last Post: 1st May 2009, 12:20 PM
  4. [PHP] MRBS config.inc.php
    By adminray in forum Web Development
    Replies: 2
    Last Post: 1st May 2009, 10:11 AM
  5. [PHP] PHP Form Generator
    By _Bat_ in forum Web Development
    Replies: 1
    Last Post: 25th March 2009, 11:39 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •