added deeply nested if/else clauses to prevent all kinds of errors concerning not enough rights to write files

git-svn-id: http://yolanda.mister-muffin.de/svn@293 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-04-10 11:57:31 +00:00
parent 2b212d3362
commit 5ab40cbe8e
2 changed files with 55 additions and 38 deletions

View file

@ -60,13 +60,18 @@ while(1)
$vwidth = int($vheight*($width/$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((int(($filesize*8) / $duration + .5) - $abitrate)/1000);
#check if the bitrate is lower than 16000 (maximum for ffmpeg)
$vbitrate = $vbitrate <= 16000 ? $vbitrate : 16000;
#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 /tmp/$id"; $ffmpeg = 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, $vbitrate, $filesize, $vwidth, $vheight, $fps, $duration, $sha, $ffmpeg;
#only insert into videos table when everything went right
if($ffmpeg == 0)
{
$filesize = -s "$root/videos/$id"; $filesize = -s "$root/videos/$id";
#add video to videos table #add video to videos table
@ -74,13 +79,10 @@ while(1)
subject, source, language, coverage, rights, license, ?, duration, ?, ?, fps, hash, 0, 0 subject, source, language, coverage, rights, license, ?, duration, ?, ?, fps, hash, 0, 0
from uploaded where id = ?}, undef, $filesize, $vwidth, from uploaded where id = ?}, undef, $filesize, $vwidth,
$vheight, $id) or interrupt $dbh->errstr; $vheight, $id) or interrupt $dbh->errstr;
}
#delete temp file #delete from uploaded table and from /tmp
unlink "/tmp/$id"; unlink "/tmp/$id";
#TODO:create torrent file
#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;
} }
else else

View file

@ -125,13 +125,18 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
$tnheight = $tnmaxheight; $tnheight = $tnmaxheight;
$tnwidth = int($tnheight*($width/$height)/2 + .5)*2; $tnwidth = int($tnheight*($width/$height)/2 + .5)*2;
system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/thumbnails/$id"; $ffthumb = system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $thumbnailsec -s ".$tnwidth."x$tnheight $root/video-stills/thumbnails/$id";
system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $previewsec $root/video-stills/previews/$id"; $ffprev = system "ffmpeg -i /tmp/$id -vcodec mjpeg -vframes 1 -an -f rawvideo -ss $previewsec $root/video-stills/previews/$id";
#if thumbnail was created successfully
if($ffthumb == 0 and $ffprev == 0)
{
$vmaxheight = 640; $vmaxheight = 640;
#check if the upload already is in the right format and smaller/equal max-width/height #check if the upload already is in the right format and smaller/equal max-width/height
if ($container eq 'ogg' and $video eq 'theora' and ($audio eq 'vorbis' or not $audio) and $height <= $vmaxheight) if ($container eq 'ogg' and $video eq 'theora' and ($audio eq 'vorbis' or not $audio) and $height <= $vmaxheight)
{
if(move("/tmp/$id", "$root/videos/$id"))
{ {
#add video to videos table #add video to videos table
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator, $dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
@ -141,10 +146,13 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
#delete from uploaded table #delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr; $dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
}
move("/tmp/$id", "$root/videos/$id"); else
{
#TODO:create torrent file #delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
die "cannot move video to $root/videos/$id - check your permissions!"
}
} }
else else
{ {
@ -157,6 +165,13 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
#print success to the user #print success to the user
print $query->redirect("index.pl?information=information_uploaded&value=$domain/video/".urlencode($query->param("DC.Title"))."/$id/"); print $query->redirect("index.pl?information=information_uploaded&value=$domain/video/".urlencode($query->param("DC.Title"))."/$id/");
} }
else
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
die "cannot create thumbnails - check your permissions!";
}
}
} }
} }
} }