added config file - third part

git-svn-id: http://yolanda.mister-muffin.de/svn@302 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-04-15 19:52:11 +00:00
parent 6b9ccd3223
commit ced190b5c9
4 changed files with 125 additions and 91 deletions

View file

@ -27,10 +27,11 @@
<string id="video_height_min">240</string> <string id="video_height_min">240</string>
<string id="video_width_max">1080</string> <string id="video_width_max">1080</string>
<string id="video_width_min">320</string> <string id="video_width_min">320</string>
<string id="video_filesize_max">204800</string><!-- in bytes --> <string id="video_filesize_max">86388736</string><!-- in bytes -->
<string id="video_filesize_min">512</string> <string id="video_filesize_min">512</string>
<string id="video_bitrate_max">6000</string> <string id="video_bitrate_max">6000</string>
<string id="video_audio_bitrate">64</string> <string id="video_audio_bitrate">64</string>
<string id="video_thumbnail_height">120</string>
<!-- settings for xml output --> <!-- settings for xml output -->
<!--<string id="xml_namespace">http://feature.yolanda.namespace.tld</string>--> <!--<string id="xml_namespace">http://feature.yolanda.namespace.tld</string>-->

View file

@ -69,6 +69,8 @@
<string id="error_upload_io">Cannot read video file</string> <string id="error_upload_io">Cannot read video file</string>
<string id="error_upload_not_a_video">File is not a video</string> <string id="error_upload_not_a_video">File is not a video</string>
<string id="error_upload_duplicate">Video has already been uploaded</string> <string id="error_upload_duplicate">Video has already been uploaded</string>
<string id="error_upload_file_too_small">The filesize of the video you uploaded is too small</string>
<string id="error_upload_file_too_big">The filesize of the video you uploaded is too big</string>
<string id=""></string> <string id=""></string>
<!-- information --> <!-- information -->

View file

@ -36,7 +36,7 @@ if($userinfo->{'username'})
$subject =~ s/\s*$//; $subject =~ s/\s*$//;
$page->{'uploadform'}->{'DC.Subject'} = $subject; $page->{'uploadform'}->{'DC.Subject'} = $subject;
if($query->param('DC.Title')&&$query->param('DC.Subject')&&$query->param('DC.Description')) if($query->param('DC.Title')&&$subject&&$query->param('DC.Description'))
{ {
$page->{'results-listing'} = ['']; $page->{'results-listing'} = [''];

View file

@ -41,13 +41,32 @@ 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, ">/tmp/$id"); open(TEMPFILE, ">/tmp/$id");
#check that nothing more than max filesize is being uploaded
while ( <$upload_filehandle> ) while ( <$upload_filehandle> )
{ {
print TEMPFILE; print TEMPFILE;
} }
close TEMPFILE; close TEMPFILE;
#check if file is too small or too big
if( -s "/tmp/$id" < $config->{"video_filesize_min"})
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
print $query->redirect("index.pl?error=error_upload_file_too_small&value=".$config->{"video_filesize_min"});
}
elsif( -s "/tmp/$id" > $config->{"video_filesize_max"})
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
print $query->redirect("index.pl?error=error_upload_file_too_big&value=".$config->{"video_filesize_max"});
}
else
{
$info = `export SDL_VIDEODRIVER="dummy"; ffplay -stats -an -vn -nodisp /tmp/$id 2>&1`; $info = `export SDL_VIDEODRIVER="dummy"; ffplay -stats -an -vn -nodisp /tmp/$id 2>&1`;
if($info =~ /ignoring/) if($info =~ /ignoring/)
@ -106,6 +125,20 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
unlink "/tmp/$id"; unlink "/tmp/$id";
print $query->redirect("index.pl?error=error_upload_invalid_stream"); print $query->redirect("index.pl?error=error_upload_invalid_stream");
} }
elsif($width < $config->{"video_width_min"})
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
print $query->redirect("index.pl?error=error_upload_video_width_too_small&value=".$config->{"video_width_min"});
}
elsif($height < $config->{"video_height_min"})
{
#delete from uploaded table
$dbh->do(qq{delete from uploaded where id = ?}, undef, $id) or die $dbh->errstr;
unlink "/tmp/$id";
print $query->redirect("index.pl?error=error_upload_video_height_too_small&value=".$config->{"video_height_min"});
}
else else
{ {
$filesize = -s "/tmp/$id"; $filesize = -s "/tmp/$id";
@ -121,8 +154,7 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
#the width/height calculation could of course be much shorter but less readable then #the width/height calculation could of course be much shorter but less readable then
#all thumbs have equal height #all thumbs have equal height
$tnmaxheight = 120; $tnheight = $config->{"video_thumbnail_height"};
$tnheight = $tnmaxheight;
$tnwidth = int($tnheight*($width/$height)/2 + .5)*2; $tnwidth = int($tnheight*($width/$height)/2 + .5)*2;
$ffthumb = 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";
@ -131,10 +163,8 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
#if thumbnail was created successfully #if thumbnail was created successfully
if($ffthumb == 0 and $ffprev == 0) if($ffthumb == 0 and $ffprev == 0)
{ {
$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 <= $config->{"video_height_max"} and $width <= $config->{"video_width_max"})
{ {
if(move("/tmp/$id", "$root/videos/$id")) if(move("/tmp/$id", "$root/videos/$id"))
{ {
@ -175,7 +205,8 @@ if($userinfo->{'id'} && $query->param("DC.Title") &&
} }
} }
} }
}
else else
{ {
print $query->redirect("index.pl?error=error_202c"); #print $query->redirect("index.pl?error=error_202c");
} }