homepage Welcome to WebmasterWorld Guest from 54.166.173.147
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Website Technology Issues
Forum Library, Charter, Moderators: phranque

Website Technology Issues Forum

    
Video Conversion script keeps timing out.need help!
How do you tell *nix to keep processing until a command is done?
JohnSka7




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

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:

#!/bin/sh
VIDEO_PATH=/Volumes/DataHD/WebServer/Documents/streaming
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.

Thanks!

 

WesleyC




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

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. :)

rocknbil




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

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.

JohnSka7




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

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.

JohnSka7




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

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

Thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Website Technology Issues
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved