1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php exec() command combine into one??

Discussion in 'PHP' started by xbat, Jan 16, 2017.

  1. #1
    Here is my code.. I have tried mutlitple things trying to find out how to combine this command into. I have looked about 5 hours trying to find this out but no such luck..

    $cmd = sprintf('ffmpeg -t 3 -ss 00:00:02 -i %s %s',$file_location,$file_name_output);
    exec($cmd);
    $file_name_output_done=$number.'_'.$file_name_edited.'.gif';
    $cmd2 = sprintf('convert %s -resize 320x240 %s',$file_name_output,$file_name_output_done);
    exec($cmd2);
    $cmd3=sprintf('convert  -font Arial -fill orange -pointsize 50 -gravity north -draw "text 0,30 \"Click Play\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done);
    exec($cmd3);
    $cmd4=sprintf('convert  -font Arial -fill orange -pointsize 16 -gravity south -draw "text 0,40 \"CLICK PLAY  VIDEO\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done);
    exec($cmd4);
    PHP:

    So I have all this above.. How can I combine this into one command? I tried to combine 2 alone and it didn't work then I tried other things and still no luck...
    Stuff I tried
    combined 3 & 4
    $cmd3=sprintf('convert  -font Arial -fill orange -pointsize 50 -gravity north -draw "text 0,30 \"Click Play\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done,'convert  -font Arial -fill orange -pointsize 16 -gravity south -draw "text 0,40 \"CLICK PLAY FOR COMPLETE VIDEO\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done);
    exec($cmd3);
    PHP:



    //then I tried this but the text only shows up in part of the video....
    $cmd3=sprintf('convert  -font Arial -fill orange -pointsize 50 -gravity north -draw "text 0,30 \"Click Play\"" -gravity Center %s %s convert  -font Arial -fill orange -pointsize 16 -gravity south -draw "text 0,40 \"CLICK PLAY FOR COMPLETE VIDEO\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done,$file_name_output_done,$file_name_output_done);
    exec($cmd3);
    PHP:

     
    Solved! View solution.
    xbat, Jan 16, 2017 IP
  2. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #2
    You may create a shell script files using all your command. Adding +X permission. Running it using exec or shell_exec and then delete the script file once the work is done.
     
    MayurGondaliya, Jan 30, 2017 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Can you please provide a example? Or point me in the right direction.
     
    xbat, Jan 31, 2017 IP
  4. #4
    Add a semicolon between any two lines.

    E.g.
    exec ('cd /');
    exec ('cd /home');

    is the same as
    exec ('cd /; cd /home');
     
    pigpromoter, Feb 10, 2017 IP
  5. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #5
    thank you so much
     
    xbat, Feb 11, 2017 IP
  6. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #6
    $cmd_full=$cmd.'; '.$cmd2.'; '.$cmd3.'; '.$cmd4;
    exec($cmd_full);


    ----------------------

    also tried -

    exec($cmd,$cmd2,$cmd3,$cmd4);

    this did not work... :(
     
    xbat, Feb 28, 2017 IP
  7. pigpromoter

    pigpromoter Well-Known Member

    Messages:
    542
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    165
    #7
    log the outputs to see what's wrong
    exec ($cmd_full . ' 1>/path/to/log 2>/path/to/log');

    then analyze /path/to/log
     
    pigpromoter, Feb 28, 2017 IP
  8. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #8
    I get a php error. Not command error. I am using a sprintf which it doesn't seem to like in that case... Im not sure what else to do. Not unless I can input the values in a different way through php without using a sprintf
     
    xbat, Mar 1, 2017 IP
  9. pigpromoter

    pigpromoter Well-Known Member

    Messages:
    542
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    165
    #9
    what was that PHP error? Does $file_name_output_done contain any space characters, commas, apostrophes etc?
     
    pigpromoter, Mar 3, 2017 IP
  10. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #10
    No its just a number for example first part 3 second part 4_44 third part a.

    for example from above -

    $cmd = sprintf('ffmpeg -t 3 -ss 00:00:02 -i %s %s',$file_location,$file_name_output);
    exec($cmd);
    $file_name_output_done=$number.'_'.$file_name_edited.'.gif';
    $cmd2 = sprintf('convert %s -resize 320x240 %s',$file_name_output,$file_name_output_done);
    exec($cmd2);
    $cmd3=sprintf('convert  -font Arial -fill orange -pointsize 50 -gravity north -draw "text 0,30 \"Click Play\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done);
    exec($cmd3);
    $cmd4=sprintf('convert  -font Arial -fill orange -pointsize 16 -gravity south -draw "text 0,40 \"CLICK PLAY  VIDEO\"" -gravity Center %s %s',$file_name_output_done,$file_name_output_done);
    exec($cmd4);
    PHP:
     
    xbat, Mar 3, 2017 IP
  11. pigpromoter

    pigpromoter Well-Known Member

    Messages:
    542
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    165
    #11
    Well, what's this error?

    try without sprintf then.
    
    $cmd = 'ffmpeg -t 3 -ss 00:00:02 -i ' . $file_location . ' ' . $file_name_output;
    
    PHP:
     
    pigpromoter, Mar 5, 2017 IP
  12. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #12
    I think that may work as silly as that sounds.. haha thanks I will try that. (i did try something like that but I believe my quotes and periods may have been in the wrong spot.
     
    xbat, Mar 5, 2017 IP