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:
parent
2b212d3362
commit
5ab40cbe8e
2 changed files with 55 additions and 38 deletions
|
@ -60,27 +60,29 @@ 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;
|
||||||
|
|
||||||
$filesize = -s "$root/videos/$id";
|
#only insert into videos table when everything went right
|
||||||
|
if($ffmpeg == 0)
|
||||||
|
{
|
||||||
|
$filesize = -s "$root/videos/$id";
|
||||||
|
|
||||||
|
#add video to videos table
|
||||||
|
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
||||||
|
subject, source, language, coverage, rights, license, ?, duration, ?, ?, fps, hash, 0, 0
|
||||||
|
from uploaded where id = ?}, undef, $filesize, $vwidth,
|
||||||
|
$vheight, $id) or interrupt $dbh->errstr;
|
||||||
|
}
|
||||||
|
|
||||||
#add video to videos table
|
#delete from uploaded table and from /tmp
|
||||||
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
|
||||||
subject, source, language, coverage, rights, license, ?, duration, ?, ?, fps, hash, 0, 0
|
|
||||||
from uploaded where id = ?}, undef, $filesize, $vwidth,
|
|
||||||
$vheight, $id) or interrupt $dbh->errstr;
|
|
||||||
|
|
||||||
#delete temp file
|
|
||||||
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
|
||||||
|
|
|
@ -125,37 +125,52 @@ 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";
|
||||||
|
|
||||||
$vmaxheight = 640;
|
#if thumbnail was created successfully
|
||||||
|
if($ffthumb == 0 and $ffprev == 0)
|
||||||
#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)
|
|
||||||
{
|
{
|
||||||
#add video to videos table
|
$vmaxheight = 640;
|
||||||
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
|
||||||
subject, source, language, coverage, rights, license, ?, ?, ?, ?, ?, ?, 0, 0
|
|
||||||
from uploaded where id = ?}, undef, $filesize, $duration, $width,
|
|
||||||
$height, $fps, $sha, $id) or die $dbh->errstr;
|
|
||||||
|
|
||||||
#delete from uploaded table
|
|
||||||
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
|
|
||||||
|
|
||||||
move("/tmp/$id", "$root/videos/$id");
|
#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(move("/tmp/$id", "$root/videos/$id"))
|
||||||
|
{
|
||||||
|
#add video to videos table
|
||||||
|
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
||||||
|
subject, source, language, coverage, rights, license, ?, ?, ?, ?, ?, ?, 0, 0
|
||||||
|
from uploaded where id = ?}, undef, $filesize, $duration, $width,
|
||||||
|
$height, $fps, $sha, $id) or die $dbh->errstr;
|
||||||
|
|
||||||
|
#delete from uploaded table
|
||||||
|
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#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
|
||||||
|
{
|
||||||
|
#write all valueable information to database so the daemon can fetch it
|
||||||
|
$dbh->do(qq{update uploaded set filesize = ?, duration = ?, width = ?,
|
||||||
|
height = ?, fps = ?, hash = ? where id = ?}, undef, $filesize, $duration, $width,
|
||||||
|
$height, $fps, $sha, $id) or die $dbh->errstr;
|
||||||
|
}
|
||||||
|
|
||||||
#TODO:create torrent file
|
#print success to the user
|
||||||
|
print $query->redirect("index.pl?information=information_uploaded&value=$domain/video/".urlencode($query->param("DC.Title"))."/$id/");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#write all valueable information to database so the daemon can fetch it
|
#delete from uploaded table
|
||||||
$dbh->do(qq{update uploaded set filesize = ?, duration = ?, width = ?,
|
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
|
||||||
height = ?, fps = ?, hash = ? where id = ?}, undef, $filesize, $duration, $width,
|
die "cannot create thumbnails - check your permissions!";
|
||||||
$height, $fps, $sha, $id) or die $dbh->errstr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#print success to the user
|
|
||||||
print $query->redirect("index.pl?information=information_uploaded&value=$domain/video/".urlencode($query->param("DC.Title"))."/$id/");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue