\n"; echo "\n"; //run this from the command line as 'php vlog_public.php' //phpinfo(); //ipath is input path - can be DVD or harddrive location //set ipath to where ever all the AVIs from the digital camera are to be compressed to flv for the flash player //opath will be a local mirror with all the compressed videos sorted by yyyy/mm/dd //$ipath='/root/videos/web200711/'; //$ipath='/mnt/dvd/'; $ipath='/home/camera/'; //$opath='/root/videos/web200711/'; $opath='/root/videos/'; //convert all folders and files from DVD (or harddrive) if (1) { //use to test command-line //if ($_POST["send"]=="Process videos") { echo 'Importing and converting videos:
'; flush(); //ob_flush(); //startfile= //=filename, do not mencoder .avi files until filename preg_matches, //''=mencoder all .avi files, //'0'=mencoder no .avi files $startavifile='';//'massmentum';//bell_in_vacuum';//'music_go'; $startfile='';//';//vlog20071226-2157'; //because process_videos is recursive, we need to write the startfile variables to a file $fp=fopen($opath.'startfile.txt',"w"); if (strlen($startfile)==0) { fwrite($fp,"0"); } else { fwrite($fp,$startfile); } fclose($fp); $fp=fopen($opath.'startavifile.txt',"w"); if (strlen($startavifile)==0) { fwrite($fp,"0"); } else { fwrite($fp,$startavifile); } fclose($fp); process_videos($ipath,$opath); } else { echo '


'; echo '
'; echo ''; echo '
'; } echo "\n"; echo "\n"; function process_videos($ipth,$opth) { //if ($ipth!='.' && $ipth!='..' && is_dir($ipth)) { if (is_dir($ipth)) { if ($dh = opendir($ipth)) { $foundvideo=0; while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $fp=fopen($opth.'startfile.txt',"r"); $startfile=fread($fp,255); fclose($fp); if ($startfile=='0') { $startfile='';} $fp=fopen($opth.'startavifile.txt',"r"); $startavifile=fread($fp,255); fclose($fp); if ($startavifile=='0') { $startavifile='';} //filetype=dir or file - go into any dirs $ftype=filetype($ipth.$file); //echo "filename: $file : filetype: ".$ftype."\n
"; if ($ftype=="dir") { echo 'calling process_videos with '.$ipth.$file.'/
'; echo "startfile=$startfile startavifile=$startavifile
"; process_videos($ipth.$file.'/',$opth); } else { if (eregi(".avi",$file)) { $foundvideo=1; // open some file for reading //$file = 'MVI_0118o.avi'; //$file = 'MVI_0119o.avi'; //PHP needs to make a fileitime - for file creation time //even stat does not return file creation time //but yet the creation time is listed in an ls -l // $filedate=filectime($ipth.$file); //echo date("F d Y H:i:s",$filedate); $filedate = exec("ls --full-time $ipth$file | awk '{print $6}'"); $filetime = exec("ls --full-time $ipth$file | awk '{print $7}'"); $filetime=preg_replace("/\.[0-9]+$/","",$filetime); //echo $filedate.chr(10); //echo $filetime.chr(10); $filedate=strtotime($filedate.' '.$filetime); $fyr=date("Y",$filedate); $fmn=date("m",$filedate); $fdy=date("d",$filedate); $fhr=date("H",$filedate); $fmi=date("i",$filedate); $fms=date("s",$filedate); //echo "year=$fyr month=$fmn day=$fdy
"; if (!file_exists($opth.$fyr)) { echo 'create folder '.$opth.$fyr.'
'; mkdir($opth.$fyr); //make year folder } if (!file_exists($opth.$fyr.'/'.$fmn)) { echo 'create folder '.$opth.$fyr.'/'.$fmn.'
'; mkdir($opth.$fyr.'/'.$fmn); //make month folder } if (!file_exists($opth.$fyr.'/'.$fmn.'/'.$fdy)) { echo 'create folder '.$opth.$fyr.'/'.$fmn.'/'.$fdy.'
'; mkdir($opth.$fyr.'/'.$fmn.'/'.$fdy); //make day folder } //create new filename $outfile='vlog'.$fyr.$fmn.$fdy.'-'.$fhr.$fmi.$fms.'.flv'; $outpath= $opth.$fyr.'/'.$fmn.'/'.$fdy.'/'; //list($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks)= stat($ipth.$file); // echo 'atime='.$atime.'
'; // echo 'size='.$size.'
'; // echo 'ctime='.$ctime.'
'; // echo 'ipth='.$ipth.' file='.$file.'
'; //$size = exec("du -sm /your/path | awk '{print $1}'"); //$s1='ls -l '.$ipth.$file.' | awk "{print $5}"'; // $s1='ls -l '.$ipth.$file;//.' | awk "{print $5}"'; // echo 's1='.$sl.'
'; // $fdate=exec($s1); // echo 'fdate='.$fdate.'
'; // echo 'ls ...
'; $fp = fopen($ipth.$file,'r'); //echo 'after file open'.$fp.'
'; //echo (ini_get("safe_mode"))? 'Enabled':'Disabled'; //$nfile=preg_replace("/\.avi/",".flv",$file); //convert each avi file $s1='/usr/bin/mencoder '.$ipth.$file.' -of lavf -ovc lavc -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale=320:240 -noskip -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -o '.$outpath.$outfile; //$s1='ffmpeg -i '.$ipath.$file.' '.$opath.$nfile; //$s1='mencoder '.$fline.' -of lavf -ovc lavc -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale=320:240 -noskip -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -o '.$fline2; //echo '
'.$s1.'
'.chr(10); //echo '
'; //make folder based on yyyy/mm/dd if does not exist $ftpflv=1; //ftp flv files //ob_flush(); //comment this line to not mencoder avi to flv if (strlen($startfile)>0) { if (preg_match('/'.preg_quote($startfile,"/").'/',$outfile)) { echo 'FOUND STARTFILE '.$startfile.'
'; $startfile='0'; $fp=fopen($opth.'startfile.txt',"w"); fwrite($fp,$startfile); fclose($fp); $startfile=''; } else { $ftpflv=0; } } //strlen startfile if (strlen($startavifile)>0) { if (preg_match('/'.preg_quote($startavifile,"/").'/',$file)) { //found video to start processing echo 'FOUND STARTAVIFILE '.$startavifile.'
'; $startavifile='0'; //cant write 0 bytes process all later files $fp2=fopen($opth.'startavifile.txt',"w"); fwrite($fp2,$startavifile); fclose($fp2); $startavifile=''; //cant write 0 bytes process all later files } else { $ftpflv=0; } } //strlen startavifile //if (strlen($startfile)==0 && strlen($startavifile)==0) { if (strlen($startfile)==0 && strlen($startavifile)==0) { //rename file to date yyyymmdd_hhmmss.flv echo 'Converting '.$ipth.$file.' to '.$outpath.$outfile.'
'.chr(10); flush(); $lastline=exec($s1,$retval); } //for($i=0;$i'; //} //echo $lastline.'
'; fclose($fp); //make JPG $outjfile=preg_replace("/.flv/",".jpg",$outfile); echo 'Create JPEG '.$outjfile.'
'; $s1='ffmpeg -i '.$ipth.$file.' -vframes 1 -f image2 '.$outpath.$outjfile; $lastline=exec($s1,$retval); //because path changes depending on file name, easier to FTP each file //but need to FTP as thread? //what happens when ftp_video is called, but is already logged in and sending a video? hopefully a new thread is created //processing waits until ftp is complete //in future perhaps threads would allow both to run simulataneously and reduce the time by half if ($ftpflv) { ftp_video($fyr,$fmn,$fdy,$opth,$outpath,$outfile); } } //avi } //not dir - is file } //not . or .. } //while closedir($dh); } //$dh } //is_dir(ipath) } //function process_videos //ftp could take an array and send after processing //but perhaps time saving to send while processing if possible function ftp_video($yr,$mn,$dy,$odir,$ldir,$file) { //create vlog folder for this to work $ftpflv=1; //set to 0 to skip uploading any flv files - but still upload jpg, htm, xspf, etc $ftpfail=0; $ftp_server="ftp.yourURL.com"; $ftp_user_name="YourUserID"; $ftp_user_pass="YourPassword"; $ftpdir="/public_html/vlog"; $cr=chr(10); //echo 'Uploading converted videos in folder: '.$outpath.' to yourURL.com
'; echo 'Uploading converted video: '.$ldir.$file.' to yourURL.com
'; flush(); //ob_flush(); // set up basic connection $conn_id = ftp_connect($ftp_server); //echo 'conn_id='.$conn_id.'
'; // login with username and password $login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass); //ftp disconnects sometimes, if anything fails, call ftp_video again //make year, month and day folders if they do not exist yet $contents = ftp_nlist($conn_id,$ftpdir); $foundyr=0; for($i=0;$i'; if ($ftpflv && !$ftpfail) { echo 'uploading video file: '.$ftpdir2.'/'.$file.' ...
'; flush(); if (ftp_fput($conn_id,$ftpdir2.'/'.$file, $fp, FTP_BINARY)) { echo "Successfully uploaded $ftpdir2/$file
\n"; } else { echo "There was a problem while uploading $ftpdir2/$file
\n"; $ftpfail=1; } } //ftpflv /* // try to upload $file if (ftp_fput($conn_id,$ftpdir.'/'.$file, $fp, FTP_BINARY)) { echo "Successfully uploaded $ftpdir/$file
\n"; } else { echo "There was a problem while uploading $ftpdir/$file
\n"; } */ fclose($fp); //upload .jpg file $jfile=preg_replace("/.flv/",".jpg",$file); $fp=fopen($ldir.$jfile,"r"); if (!$ftpfail && ftp_fput($conn_id,$ftpdir2.'/'.$jfile,$fp, FTP_BINARY)) { // echo "Successfully uploaded $file
\n"; echo "Successfully uploaded $ftpdir2/$jfile
\n"; } else { // echo "There was a problem while uploading $file
\n"; echo "There was a problem while uploading $ftpdir2/$jfile
\n"; } fclose($fp); flush(); //ob_flush(); $t1=''.$cr; $t1.=''.$cr; $t1.='Ted Huntington VLOG '.$mn.'/'.$dy.'/'.$yr.''.$cr; $t1.='http://yourURL.com/'.$cr; $t1.='Ted Huntington'.$cr; $t1.=''.$cr; //for each file create a link to download //get all files in this folder, create and FTP a player and playlist file $contents = ftp_nlist($conn_id,$ftpdir2); $s2=''; $numvids=0; for($i=0;$i'.$contents[$i].'
'.$cr; //add track to playlist for each file in folder $t1.=''.$cr; $t1.='http://www.yourURL.com/vlog/'.$yr.'/'.$mn.'/'.$dy.'/'.$contents[$i].''.$cr; $jfile=preg_replace("/.flv/",".jpg",$contents[$i]); $t1.='http://www.yourURL.com/vlog/'.$yr.'/'.$mn.'/'.$dy.'/'.$jfile.''.$cr; $t1.=''.$contents[$i].''.$cr; $t1.=''.$cr; } //preg_match } //for i //create the index.htm file $s1=''.$cr; $s1.=''.$cr; $s1.= '
VLOG
'.$cr; $s1.= '
'.$mn.'/'.$dy.'/'.$yr.'
'.$cr; //$s1.= '
Year '.$yr.'
'.$cr; //$s1.= '
Month '.$mn.'
'.$cr; //$s1.= '
Day '.$dy.'
'.$cr; $s1.= '

'.$cr; $s1.= '\n"; echo "Successfully uploaded $ftpdir2/index.htm
\n"; } else { // echo "There was a problem while uploading $file
\n"; echo "There was a problem while uploading $ftpdir2/index.htm
\n"; } fclose($fp); //FTP .xspf file $fp=fopen($ldir.'vlog'.$yr.$mn.$dy.'.xspf',"r"); if (!$ftpfail && ftp_fput($conn_id,$ftpdir2.'/vlog'.$yr.$mn.$dy.'.xspf',$fp, FTP_BINARY)) { // echo "Successfully uploaded $file
\n"; echo "Successfully uploaded $ftpdir2/vlog$yr$mn$dy.xspf
\n"; } else { // echo "There was a problem while uploading $file
\n"; echo "There was a problem while uploading $ftpdir2/vlog$yr$mn$dy.xspf
\n"; } fclose($fp); flush(); //ob_flush(); if (!$foundyr) { //made new year folder update index.htm with latest months ftp_chdir($conn_id,$ftpdir.'/'.$yr); //$s1=''.$cr; $s1.=''.$cr; $s1.='
VLOG
'.$cr; $s1.='

'.$cr; $s1.='
Years:
'.$cr; //for each year list $contents = ftp_nlist($conn_id,$ftpdir); for($i=0;$i'.$contents[$i].'
'.$cr; } //preg } //for $i $s1.=''.$cr; $s1.=''.$cr; $fp=fopen($odir.'/index.htm',"w"); fwrite($fp,$s1); fclose($fp); //upload index.htm for available years $fp=fopen($odir.'/index.htm',"r"); if (ftp_fput($conn_id,$ftpdir.'/index.htm',$fp,FTP_ASCII)) { // echo "Successfully uploaded $file
\n"; echo "Successfully uploaded $ftpdir/index.htm
\n"; } else { // echo "There was a problem while uploading $file
\n"; echo "There was a problem while uploading $ftpdir/index.htm
\n"; $ftpfail=1; } fclose($fp); flush(); } //foundyr if (!$foundmn) { //ftp_chdir($conn_id,$ftpdir.'/'.$yr); //send .php file to list available months $s1=''.$cr; $s1.=''.$cr; $s1.= '
VLOG
'.$cr; $s1.= '
Year '.$yr.'
'.$cr; $s1.= '

'.$cr; $s1.= '
Months:
'.$cr; //for each month list $contents = ftp_nlist($conn_id,$ftpdir.'/'.$yr); for($i=0;$i'.$contents[$i].'
'.$cr; } //preg } //for $i $s1.=''.$cr; $s1.=''.$cr; $fp=fopen($odir.'/'.$yr.'/index.htm',"w"); fwrite($fp,$s1); fclose($fp); //upload index.htm for year $fp=fopen($odir.'/'.$yr.'/index.htm',"r"); if (!$ftpfail && ftp_fput($conn_id,$ftpdir.'/'.$yr.'/index.htm',$fp,FTP_ASCII)) { echo "Successfully uploaded $ftpdir/$yr/index.htm
\n"; } else { echo "There was a problem while uploading $ftpdir/$yr/index.htm
\n"; $ftpfail=1; } fclose($fp); flush(); }//foundmn if (!$founddy) { //made day folder //send .htm file to list available days in month $s1=''.$cr; $s1.=''.$cr; $s1.= '
VLOG
'.$cr; $s1.= '
Year '.$yr.'
'.$cr; $s1.= '
Month '.$mn.'
'.$cr; $s1.= '

'.$cr; $s1.= '
Days:
'.$cr; //for each month list $contents = ftp_nlist($conn_id,$ftpdir.'/'.$yr.'/'.$mn); for($i=0;$i'.$contents[$i].'
'.$cr; } //preg } //for $i $s1.=''.$cr; $s1.=''.$cr; $fp=fopen($odir.'/'.$yr.'/'.$mn.'/index.htm',"w"); fwrite($fp,$s1); fclose($fp); //upload index.php for month $fp=fopen($odir.'/'.$yr.'/'.$mn.'/index.htm',"r"); if (!$ftpfail && ftp_fput($conn_id,$ftpdir.'/'.$yr.'/'.$mn.'/index.htm',$fp,FTP_ASCII)) { // echo "Successfully uploaded $file
\n"; echo "Successfully uploaded $ftpdir/$yr/$mn/index.htm
\n"; } else { // echo "There was a problem while uploading $file
\n"; echo "There was a problem while uploading $ftpdir/$yr/$mn/index.htm
\n"; $ftpfail=1; } fclose($fp); flush(); } //founddy } //flv // close the connection and the file handler ftp_close($conn_id); if ($ftpfail) { //ftp failed, call function again echo 'FTP failed, trying again
'; ftp_video($yr,$mn,$dy,$odir,$ldir,$file); } } //ftp_video ?>