added variable video bitrate depending on video source, better daemin logging, enabled download resuming, set default locale when wrong http-accept-header ist started

git-svn-id: http://yolanda.mister-muffin.de/svn@228 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-01-05 13:57:02 +00:00
parent 37b75b5801
commit 5b68ed57c5
5 changed files with 71 additions and 19 deletions

View file

@ -42,23 +42,53 @@ if($query->param('id'))
{
#seems we only want to watch it - update viewcount
$dbh->do(qq{update videos set viewcount=viewcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
print $query->header(-type=>'application/ogg',
-length=> -s "$root/videos/".$query->param('id'));
}
else
{
#video is being downloaded - update downloadcount
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
print $query->header(-type=>'application/ogg',
-length=> -s "$root/videos/".$query->param('id'),
-attachment=>$title.".ogv");
}
#in both cases - do some slurp-eaze to the browser
open(FILE, "<$root/videos/".$query->param('id'));
print <FILE>;
$filesize = -s "$root/videos/".$query->param('id');
$range = $query->http('range');
$range =~ s/bytes=([0-9]+)-/$1/;
#if a specific range is requested send http partial content headers and seek in the inputfile
if($range)
{
#if $range is equal or more than filesize throw http 416 header
if($range >= $filesize)
{
print $query->header(-status=>'416 Requested Range Not Satisfiable');
}
else
{
print $query->header(-type=>'application/ogg',
-content_length=> $filesize-$range,
-status=>'206 Partial Content',
-attachment=>$title.".ogv",
-accept_ranges=> "bytes",
-content_range=> "bytes $range-".($filesize-1)."/$filesize"
);
seek FILE, $range, 0;
}
}
else
{
print $query->header(-type=>'application/ogg',
-content_length=> $filesize,
-attachment=>$title.".ogv"
);
}
while (my $BytesRead = read (FILE, $buff, 8192))
{
print $buff;
}
close(FILE);
}
else

View file

@ -35,6 +35,10 @@ sub get_page_array
else
{
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
unless($page->{'locale'})
{
$page->{'locale'} = "en_us";
}
}
$page->{'username'} = $userinfo->{'username'};

View file

@ -27,7 +27,7 @@
<!-- front page -->
<string id="button_find">Find</string>
<string id="button_lucky">Instant Access</string>
<string id="button_advanced">Avanced Search</string>
<string id="button_advanced">Advanced Search</string>
<string id="query_latestadditions">latest additions</string>
<string id="query_mostdownloads">most downloaded</string>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<strings>

View file

@ -21,7 +21,10 @@ sub appendlog
{
if (open(FILE, ">>$LOG"))
{
print FILE scalar(localtime)." ".$$." ".join(" ",@_)."\n";
print FILE scalar(localtime)." ".$$."\n";
print "------------------------------------\n";
print join("\n",@_)."\n";
print "------------------------------------\n\n";
close FILE;
}
}
@ -57,7 +60,9 @@ while(1)
if($info =~ /ignoring/)
{
appendlog $id, "invalid stream";
appendlog "id: $id",
"error: invalid stream",
"ffplay msg: $info";
#write status 2 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
@ -65,7 +70,9 @@ while(1)
}
elsif ($info =~ /I\/O error occured/)
{
appendlog $id, "file not found";
appendlog "id: $id",
"error: file not found",
"ffplay msg: $info";
#write status 3 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 3, $id) or interrupt $dbh->errstr;
@ -73,7 +80,9 @@ while(1)
}
elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
{
appendlog $id, "file is no video";
appendlog "id: $id",
"error: file is of unknown format",
"ffplay msg: $info";
#write status 4 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 4, $id) or interrupt $dbh->errstr;
@ -94,7 +103,8 @@ while(1)
#if so, then video is a duplicate
if($resultid)
{
appendlog "$id, video already uploaded: $resultid";
appendlog "id: $id",
"error: video already uploaded: $resultid";
#write status 5 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 5, $id) or interrupt $dbh->errstr;
@ -110,7 +120,12 @@ while(1)
if(!$audio or !$video or !$duration)
{
appendlog $id, "a stream is missing or video is corrupt";
appendlog "id: $id",
"error: error: stream is missing or video is corrupt",
"audio: $audio",
"video: $video",
"duration: $duration",
"ffplay msg: $info";
#write status 2 to uploaded table
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
@ -118,7 +133,6 @@ while(1)
}
else
{
#TODO: maybe delete entry from uploaded table after successful upload?
$filesize = -s "$root/tmp/$id";
#convert hh:mm:ss.s duration to full seconds - thanks perl for making this so damn easy!
@ -158,9 +172,13 @@ while(1)
#calculate video width
$vheight = $vmaxheight <= $height ? $vmaxheight : $height;
$vwidth = int($vheight*($width/$height)/2 + .5)*2;
$abitrate = 64;
$vbitrate = int($filesize*8) / $duration + .5) - $abitrate;
#TODO: addmetadata information
system "ffmpeg2theora --optimize --videobitrate 1000 --audiobitrate 64 --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 $root/tmp/$id";
appendlog $id, $audio, $video, $vwidth, $vheight, $fps, $duration, $sha;
$filesize = -s "$root/videos/$id";