Welcome to WebmasterWorld Guest from

Forum Moderators: phranque

Message Too Old, No Replies

Video Conversion script keeps timing out.need help!

How do you tell *nix to keep processing until a command is done?

1:57 pm on Jun 12, 2008 (gmt 0)

5+ Year Member

Hello everyone,

I'm in the process of making a video conversion service for my job (webmaster for a school district). We want to be able to take our Board of Ed meetings and convert them from their file format (which, unfortunately, changes) to flv files.

I went ahead and created a PHP script which will find all files in a specific directory (uploads) and list them. When you click on a file name, PHP executes the following:

$video = popen("nohup /usr/local/convert_video ".$_GET['file']." ".str_replace(" ", "_", $final_file_name[0])." > /Volumes/DataHD/Webserver/Documents/streaming/queue/what_happened.txt &", "w");

which submits the current file name and what the output file name should be. The "convert_video" shell script does the following:

chflags nouchg $VIDEO_PATH/upload/$1
chown www $VIDEO_PATH/upload/$1
chgrp www $VIDEO_PATH/upload/$1
chmod 775 $VIDEO_PATH/upload/$1
mv $VIDEO_PATH/upload/$1 $VIDEO_PATH/queue/$1
DURATION=`/usr/local/ffmpeg -i $VIDEO_PATH/queue/$1 2>&1 grep "Duration" grep -o "[0-5][0-9]:[0-5][0-9]:[0-5][0-9].[0-3]"`
/usr/local/ffmpeg -i $VIDEO_PATH/queue/$1 -t $DURATION -ab 56k -s 640x480 -ar 22050 -ac 1 -vcodec flv -b 500k -y -map_meta_data $VIDEO_PATH/queue/$1:$VIDEO_PATH/queue/$2.flv $VIDEO_PATH/$2.flv
/usr/local/flvtool2 -Ukv $VIDEO_PATH/$2.flv $VIDEO_PATH/$2.flv
chown www $VIDEO_PATH/$2.flv
chgrp www $VIDEO_PATH/$2.flv
chmod 775 $VIDEO_PATH/$2.flv
php /Volumes/DataHD/WebServer/Documents/_admin/video_status.php 3

If I execute this script via SSH, I have no problems; the video converts and everything is great. However, when I try to launch this via the web browser, it is a different story. The process starts up, but ffmpeg quits after about 60~80mb of conversion, and then continues on through the rest of the shell script. I thought that the nohup command that PHP issued would allow the script to keep running (even if the issuing user logged off the machine). I also threw in the duration figuring it would help force ffmpeg to continue until a defined end, but no such luck.

I'm not really sure if the problem is in the PHP, the shell script, ffmpeg, etc, so if anyone has any idea how I can figure this out, I'd really appreciate it.


1:37 pm on Jun 13, 2008 (gmt 0)

5+ Year Member

The problem is probably PHP. Try setting this at the top of your code:

set_time_limit( 9999999 );

Or just replace the 9s with some other large number. :)

7:14 pm on Jun 13, 2008 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The process starts up, but ffmpeg quits after about 60~80mb of conversion, and then continues on through the rest of the shell script

I have had some large projects that would time out mid-stream, but they were in perl. In either case (perl or php,) you may want to look at fork. Fork initiates a parent and child process; your browser request is the parent, then you fork a child process to do the upload. The server response from the parent process is semi-immediate and allows the time consuming tasks to proceed in the background.

Worth having a look at.

1:42 pm on Jun 15, 2008 (gmt 0)

5+ Year Member

I'll look into both suggestions, but my assumption was that I was already passing the command from PHP to the OS itself with the '&' in the popen command.

The funny part is that I know the main shell script doesn't time out...every command after the ffmpeg keeps working (a launch of flv2tool for meta data, another ffmpeg to grab a screen shot, resetting permissions and an email to say conversion is done), so that's what is leading me to believe it's a shell level problem with having a script run so long while not attached to a session.

3:36 pm on Jun 18, 2008 (gmt 0)

5+ Year Member

WesleyC, you had it right. Everything is working great with it now.



Featured Threads

Hot Threads This Week

Hot Threads This Month