use /tmp for temporary stuff

git-svn-id: http://yolanda.mister-muffin.de/svn@233 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-02-11 12:42:19 +00:00
parent cc83540aa2
commit f7ea26799b
2 changed files with 21 additions and 18 deletions

View file

@ -58,7 +58,7 @@ while(1)
if($id) if($id)
{ {
$info = `export SDL_VIDEODRIVER="dummy"; ffplay -stats -an -vn -nodisp $root/tmp/$id 2>&1`; $info = `export SDL_VIDEODRIVER="dummy"; ffplay -stats -an -vn -nodisp /tmp/$id 2>&1`;
if($info =~ /ignoring/) if($info =~ /ignoring/)
{ {
@ -68,7 +68,7 @@ while(1)
#write status 2 to uploaded table #write status 2 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
unlink "$root/tmp/$id"; unlink "/tmp/$id";
} }
elsif ($info =~ /I\/O error occured/) elsif ($info =~ /I\/O error occured/)
{ {
@ -78,7 +78,7 @@ while(1)
#write status 3 to uploaded table #write status 3 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 3, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 3, $id) or interrupt $dbh->errstr;
unlink "$root/tmp/$id"; unlink "/tmp/$id";
} }
elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/) elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
{ {
@ -88,12 +88,12 @@ while(1)
#write status 4 to uploaded table #write status 4 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 4, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 4, $id) or interrupt $dbh->errstr;
unlink "$root/tmp/$id"; unlink "/tmp/$id";
} }
else else
{ {
$sha = new Digest::SHA(256); $sha = new Digest::SHA(256);
$sha->addfile("$root/tmp/$id") or die "cannot open $root/tmp/$id"; $sha->addfile("/tmp/$id");
$sha = $sha->hexdigest; $sha = $sha->hexdigest;
#check if this hash is already in database #check if this hash is already in database
@ -110,7 +110,7 @@ while(1)
#write status 5 to uploaded table #write status 5 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 5, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 5, $id) or interrupt $dbh->errstr;
unlink "$root/tmp/$id"; unlink "/tmp/$id";
} }
else else
{ {
@ -131,11 +131,11 @@ while(1)
#write status 2 to uploaded table #write status 2 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr; $dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
unlink "$root/tmp/$id"; unlink "/tmp/$id";
} }
else else
{ {
$filesize = -s "$root/tmp/$id"; $filesize = -s "/tmp/$id";
#convert hh:mm:ss.s duration to full seconds - thanks perl for making this so damn easy! #convert hh:mm:ss.s duration to full seconds - thanks perl for making this so damn easy!
#don't want to know how this would look in python or php... hell I don't even have to create extra variables! #don't want to know how this would look in python or php... hell I don't even have to create extra variables!
@ -151,7 +151,7 @@ while(1)
$tnheight = $tnmaxheight; $tnheight = $tnmaxheight;
$tnwidth = int($tnheight*($width/$height)/2 + .5)*2; $tnwidth = int($tnheight*($width/$height)/2 + .5)*2;
system "ffmpeg -i $root/tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/$id"; system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/$id";
$vmaxheight = 640; $vmaxheight = 640;
@ -167,20 +167,21 @@ while(1)
$height, $fps, $sha, $id) or interrupt $dbh->errstr; $height, $fps, $sha, $id) or interrupt $dbh->errstr;
#move video #move video
move "$root/tmp/$id", "$root/videos/$id"; move "/tmp/$id", "$root/videos/$id";
} }
else #encode video else #encode video
{ {
#calculate video width #video height is either ther maximum video height
#TODO: ffmpeg only accepts values dividable by 8 !!! ( check that ) #or when the original is smaller than that the original height
$vheight = $vmaxheight <= $height ? $vmaxheight : $height; #check for multiple by 8
$vwidth = int($vheight*($width/$height)/2 + .5)*2; $vheight = $vmaxheight <= $height ? $vmaxheight : int($height/8 + .5)*8;
$vwidth = int($vheight*($width/$height)/8 + .5)*8;
$abitrate = 64; $abitrate = 64;
$vbitrate = int($filesize*8) / $duration + .5) - $abitrate; $vbitrate = int($filesize*8) / $duration + .5) - $abitrate;
#TODO: add metadata information #TODO: add metadata information
system "ffmpeg2theora --optimize --videobitrate $vbitrate --audiobitrate $abitrate --sharpness 0 --width $vwidth --height $vheight --output $root/videos/$id $root/tmp/$id"; system "ffmpeg2theora --optimize --videobitrate $vbitrate --audiobitrate $abitrate --sharpness 0 --width $vwidth --height $vheight --output $root/videos/$id /tmp/$id";
appendlog $id, $audio, $video, $vwidth, $vheight, $fps, $duration, $sha; appendlog $id, $audio, $video, $vwidth, $vheight, $fps, $duration, $sha;
@ -193,10 +194,12 @@ while(1)
$vheight, $fps, $sha, $id) or interrupt $dbh->errstr; $vheight, $fps, $sha, $id) or interrupt $dbh->errstr;
#delete temp file #delete temp file
#TODO: use /tmp you insensitive clod ! unlink "/tmp/$id";
unlink "$root/tmp/$id";
} }
#create torrent file
#delete from uploaded table #delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or interrupt $dbh->errstr; $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or interrupt $dbh->errstr;
} }

View file

@ -41,7 +41,7 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
#save uploaded file into temppath #save uploaded file into temppath
$upload_filehandle = $query->upload("file"); $upload_filehandle = $query->upload("file");
open(TEMPFILE, ">$root/tmp/$id") or die "cannot open $root/tmp/$id"; open(TEMPFILE, ">/tmp/$id");
while ( <$upload_filehandle> ) while ( <$upload_filehandle> )
{ {
print TEMPFILE; print TEMPFILE;