Modification inteferes with upload

I’m using the PHP script for a video web site, and have added the ability to
show the user’s avatar (that he adds to his User Profile) as his uploaded video’s Thumbnail image,
in place of the thumbnail that’s generated by the uploaded video itself
(if the User leaves his avatar blank, the thumbnail generated by the video will show).

It works successfully when the videos uploaded are short and not when the videos are longer.

When I comment-out the added code (the nine commented-out lines near the bottom of the convertor.php code -posted below), all files upload successfully and the video-generated thumbnail appears.

When I remove the commenting-out of those lines of code, only shorter videos show the avatar thumbnail, and only shorter videos(200KB for example) upload at all. Longer videos (25,000KB for example) don’t appear to have uploaded.

Any insight or suggestion will be appreciated.

//______________________________________________________________________________________________
	//_____________________________CREATE THUMBNAIL IMAGE___________________________________________

// TODO ADD MULTIPULE THUMB CODE HERE

	$output_file = $base_path.'/uploads/thumbs/'.$file_name_no_extension.'.jpg';
	$player_output_file = $base_path.'/uploads/player_thumbs/'.$file_name_no_extension.'.jpg';

//__create standard thumb_______
	$cmd = "$config[path_to_ffmpeg] -i $new_mp4 -ss $thumb_position -vframes 1 -s 120x90 -r 1 -f mjpeg $output_file";
	$output = '';
	@exec("$cmd 2>&1",$output);
capture_output($output,$cmd);

//__create large thumb for better player image_______
	$cmd = "$config[path_to_ffmpeg] -i $new_mp4 -ss $thumb_position -vframes 1 -s 560x420 -r 1 -f mjpeg $player_output_file";
	$output = '';
	@exec("$cmd 2>&1",$output);
	capture_output($output,$cmd);

//__check if thumbnail was created_______
	if(!file_exists($output_file)) {

  	$cmd = "$config[path_to_ffmpeg] -i $new_mp4 -ss $thumb_position -vframes 1 -s 120x90 -r 1 -f image2 $output_file";
    	$output = '';
   	@exec("$cmd 2>&1",$output);
    	capture_output($output,$cmd);
	}

//__check if thumbnail is 0 bytes_________
	if(filesize($output_file) == 0) {
  	$second = '00:00:04';
    	$cmd = "$config[path_to_ffmpeg] -i $new_mp4 -deinterlace -an -ss $second -vframes 1 -s 120x90 -r 1 -y -vcodec mjpeg -f mjpeg $output_file";
    	$output = '';
    	@exec("$cmd 2>&1",$output);
    	capture_output($output,$cmd);
	}

    //____________________________________________________________________
     	//___JUMP START DATABASE______________________________________________
$sql_test = 'SELECT * FROM videos LIMIT 1';

	if(!mysql_query($sql_test)) {
  	include_once ('classes/mysql.inc.php');
    	@mysql_close();
    	    @mysql_connect($config["hostname"],$config["dbusername"],$config["dbpassword"],true);
    	@mysql_select_db($config["dbname"]);
	}

//___________________________________________________________________
	//___UPDATE THE DATABASE_____________________________________________

	//__set to just pending______
	$sql = "UPDATE videos SET approved='pending' WHERE video_id = '$raw_video'";
	@mysql_query($sql);

//__reset video id - remove extension______
	$sql = "UPDATE videos SET video_id='$file_name_no_extension' WHERE video_id = '$raw_video'";
	@mysql_query($sql);

//__set video duration_______
	$sql = "UPDATE videos SET video_length='$duration' WHERE video_id = '$file_name_no_extension'";
	@mysql_query($sql);

//__auto approve________
	if($config["auto_approve_videos"] == "yes") {
  	$sql = "UPDATE videos SET approved='yes' WHERE video_id = '$file_name_no_extension'";
   	@mysql_query($sql);
	}

//___________________________________________________________________
	//___DELETE ORIGINAL FILE_____________________________________________

	$original_file = $raw_video_path;

	if($config['delete_original'] == 'yes') {
		if(@file_exists("$new_mp4") && @file_exists("$raw_video_path")) {
        	if($new_mp4 != $raw_video_path) {
            		@unlink($raw_video_path);
        	}
    	}
	}

    //    	if($config['delete_avi'] == 'yes') if(@file_exists("$new_mp4") && @file_exists("$avi_file")) @unlink($avi_file);

	//$sql = "SELECT file_name FROM pictures WHERE user_id = $user_id LIMIT 1";

	
            //$result = mysql_query($sql);
	//$pic_file = $row['file_name'];
	//$output_file = $base_path."/uploads/thumbs/".$file_name_no_extension.'.jpg';
	//$input_file = $base_path."/pictures/".$pic_file;
	//echo "Input file = ".$input_file;
	//echo " and Output file = ".$output_file."<br>";
	//copy($input_file, $output_file);**
@mysql_close();
}
// end while

I’m guessing that possibly the longer videos time-out while this code looks in the database for the image:

 $sql = "SELECT file_name FROM pictures WHERE user_id = $user_id LIMIT 1

If this theory is in fact what is happening, can this code be modified or moved, so the video uploads before the this code goes into action?

Any ideas will be appreciated.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.