Welcome to WebmasterWorld Guest from 220.127.116.11
Forum Moderators: phranque
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)." > /Volumes/DataHD/Webserver/Documents/streaming/queue/what_happened.txt &", "w");
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.
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.
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.