Page 1 of 1
Exec in background with ffmpeg
Posted: Tue May 03, 2011 7:02 pm
by misteryyy
Hi, I am trying to encode video files with ffmpeg. I have made ajax progress bar which read data from ffmpeg output.
I have problem that I can't find the way for run cmd in background in web browser.
This cmd creates two files, one is ffmpeg log and one is file with PID. Could you help me to find out how I can run this process in background?
I am doing it whole day and I am little crazy from that, because it's part of my Bachelor project
Thanks for help Misteryyy.
Code: Select all
$cmd = "ffmpeg -i $dir -b 1000k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30 -s 640x360 -aspect 16:9 $this->dir/ogg/19_ogg_360.ogv";
exec(sprintf("%s 2> %s & echo $! >> %s", $cmd, $this->ffmpeg_log , $this->ffmpeg_log.'.pid'));
Re: Exec in background with ffmpeg
Posted: Tue May 03, 2011 8:10 pm
by Christopher
What OS is the server running? It appears to be Unix/Linux. If you have access to the server then either a cron reading a job queue or something like Gearman.
Re: Exec in background with ffmpeg
Posted: Wed May 04, 2011 4:12 am
by misteryyy
I am testing it on Ubuntu. Production server will be Gentoo. I don't know why the web browser is waiting, because i use &.
edit : I am not good at Linux. But I think that cron is for start process at exact time. I need to create this workflow.
1.User upload video file
2. Choose output video format
3. Click on button a the decode proccess will start
Re: Exec in background with ffmpeg
Posted: Wed May 04, 2011 11:39 am
by Christopher
I was proposing creating an asynchronous implementation. With either a cron or Gearman the user would upload the file and it would be put on a queue. A cron could run every minute, read the queue to check for pending jobs, and process accordingly. Gearman would be a more elegant solution. Either way the user would receive a notification, showing the status of the video on their account or via email, once the file was processed.
Re: Exec in background with ffmpeg
Posted: Wed May 04, 2011 5:17 pm
by misteryyy
In the end I am using
Code: Select all
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $this->ffmpeg_log, $this->ffmpeg_log . '.pid'));
.
I have Zend Controller which comunnitates through Ajax requests and every 5sec reads ffmpeg_log and from values creates progress bar.
I need to decode 3 format (ogv,webm,mp4) at one time. So it has delay about 1-2 sec per request but it works

. I have 14 days to finish my bachelour thesis so I don't have enought time for other experiments but cron seems like reasonable solution but I am not very good with linux. Thanks for help.
Re: Exec in background with ffmpeg
Posted: Thu May 05, 2011 9:49 am
by incubi
Just a quick note here's another way to do it.
http://nsaunders.wordpress.com/2007/01/ ... ss-in-php/
Seems to work well.