Question

I am trying to figure the best way to login via php command to a remote server and run a command to convert a FLV file into an MP3 (and then possibly moving it to the local server)?

I can always move the file later but I need to do it in this order as the remote server hosts ffmpeg.

Using this will do it locally:

exec(ffmpeg -i vid.flv -acodec copy output.mp3);

How can I do it remotely?

Thanks!

Was it helpful?

Solution

You need to do the following in order

  • Transfer the FLV via php native ftp commands
  • Create a layer in the ffmpeg server to run your commands
  • Read the response code and perform a specific action

if you send your file to the server via ftp, and then create a script on the server that you have just transferred the file to, you can ping the script with the hash code for the file, and tell it to convert.

  • Sending file via FTP (Upload Example)
  • ping server to start the conversion

the conversion script would take a file name, and then look in the local directory for the file, when it finds it, it will convert.

if you wish for the local server to know when the conversion is completed then you would also have to send an id to the conversion script and you would store that id both sides, so the server can ping back to your local script (WARNING!) with the id and you can fetch it back from server.

The reason for the warning is because its hard to get a server to ping threw to your localhost if your behind a router / firewall you would have to set up port forwarding etc on router and allow port 80 to be accessed externally.

hope this gives you some clue on how to handle this situation.

OTHER TIPS

You cannnot execute remote commands via FTP.

If you have SSH access to the machine, you can use the SSH2 extension for PHP and execute it via SSH.

Look into the SSH2 library (http://php.net/manual/en/book.ssh2.php) for how to run commands remotely, and the Curl library (http://php.net/manual/en/book.curl.php) for how to download remote files.

Write a php script and upload it to your flv conversion server. The script should:

  1. Download the flv file (via POST or another way of download) into vid.flv
  2. Run the server command "exec(ffmpeg -i vid.flv -acodec copy output.mp3);"
  3. Notify you of results whe output.mo3 is ready

You many need to change max execution time of the script (set_time_limit);

This way your script would not need to send commands via ssh.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top