0

I have very limited knowledge when it comes to console commands. What I'm trying to achieve is to execute a console command within a PHP query.

Example

<?php 

   $sql = mysql_query("SELECT * FROM `users`");
   while( $select_users = mysql_fetch_array( $sql )){

   } 

?>

The command I want to execute within the WHILE

So within this query I want to execute this command however am unsure how to achieve this; I have looked at similar questions however unsure how to implement them into my example.

ffmpeg -ss 00:00:01.01 -i /my_video_file_dir/video.flv -y -f image2 \
   -vcodec mjpeg -vframes 1 /image_dir/screenshot.jpg
Community
  • 1
  • 1

2 Answers2

0

You can use exec function of php like this

$command = 'ffmpeg -ss 00:00:01.01 -i /my_video_file_dir/video.flv -y -f image2 -vcodec mjpeg -vframes 1 /image_dir/screenshot.jpg';

exec($command);
halfer
  • 19,824
  • 17
  • 99
  • 186
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
  • 1
    Oo wow. I really didn't know it was that simple. really appreciate this response thank you very much. Will mark this as the answer shortly. –  May 30 '16 at 13:19
  • 1
    Cheers happy coding. – chandresh_cool May 30 '16 at 13:21
  • 1
    @LewisDay: if there's any chance some of this data would come from user input (e.g. the filename or options) then make sure you escape it, otherwise hackers will be able to execute arbitrary commands on your server. – halfer May 30 '16 at 14:39
0

In additional to exec you can use from following command:

$output = shell_exec($command);

This command execute command via shell and return the complete output as a string, more information: http://php.net/manual/en/function.shell-exec.php

I had same requirement like you and used from this command

Majid Abbasi
  • 1,531
  • 3
  • 12
  • 22