user974435
user974435

Reputation: 397

Exec command do not work?

Trying to convert my video using php and ffmpeg but below code doesn't give me any result or output file? Do you know why and what I am doing wrong? I should have test.webm file in return but do not have it :-(

<?php
 exec("ffmpeg -i test.mp4 -ab 96k -b:v 700k -ar 44100 -s 640x480  test.webm");
?>

Upvotes: 0

Views: 439

Answers (1)

Andrejs Cainikovs
Andrejs Cainikovs

Reputation: 28474

Nailing down exec() problems:

I'd suggest you to check what exec() is giving back:

echo exec(...);

Sure, it may happen that ffmpeg is simply not in your PATH. In this case exec() will clearly state about this, and you might need to provide the absolute path to ffmpeg, i.e.:

Linux:

exec("/path/to/ffmpeg ...");

Windows:

exec("c:\\path\\to\\ffmpeg ...");

Background task:

Other concern is that ffmpeg might run for a pretty long time, which might lead to a timeout. To avoid this problem you can execute ffmpeg in a background by adding & at the end of your command, or, for Windows, adding cmd /C in front of your actual command:

Linux:

exec("ffmpeg -i test.mp4 -ab 96k -b:v 700k -ar 44100 -s 640x480 test.webm &");

Windows:

exec("cmd /C ffmpeg -i test.mp4 -ab 96k -b:v 700k -ar 44100 -s 640x480 test.webm");

In this case exec() will return immediately, leaving ffmpeg() running in the background. ffmpeg() process will terminate as soon as it has done it's execution. But sure, you need to implement some sort of monitoring mechanism, if you want to notify the user that conversion is completed and converted file is available for download.

Upvotes: 2

Related Questions