-1

I am converting a video using ffmpeg from php in Windows using following code

<?php

exec('ffmpeg -i input.mp4 -ar 22050 -ab 32k -r 25 -s 480x360 -vcodec h264 -qscale 2.5      output.flv');

?>

While converting script hangs until conversion completed.

What can i do about it? So that it can run in background

Cody
  • 2,480
  • 5
  • 31
  • 62
  • possible duplicate of [Run a ffmpeg process in the background](http://stackoverflow.com/questions/1198052/run-a-ffmpeg-process-in-the-background) – Wooble Jan 22 '14 at 17:30
  • Are you calling this script from a website and you dont want the site to hang whilst the video encodes? – Rich Jan 22 '14 at 17:35
  • @Rich yes, Actually i am running it from localhost – Cody Jan 22 '14 at 17:37

1 Answers1

0

If your system is Linux I would just background the task by adding ' &' to the end of the command.

exec('ffmpeg -i input.mp4 -ar 22050 -ab 32k -r 25 -s 480x360 -vcodec h264 -qscale 2.5 output.flv &');

Or to be even more thorough (i.e. even if apache dies the file will still be transcoded):

exec('bash -c "exec nohup setsid ffmpeg -i input.mp4 -ar 22050 -ab 32k -r 25 -s 480x360 -vcodec h264 -qscale 2.5 output.flv > /dev/null 2>&1 &"')

Don't you have to call ffmpeg.exe on windows?

denjello
  • 531
  • 3
  • 13