From 5b68ed57c5074ac95a0e7b8847283da131fdfd0e Mon Sep 17 00:00:00 2001 From: josch Date: Sat, 5 Jan 2008 13:57:02 +0000 Subject: [PATCH] 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 --- trunk/download.pl | 46 ++++++++++++++++++++++++++++++++++-------- trunk/functions.pl | 4 ++++ trunk/locale/en-us.xml | 2 +- trunk/site/main.xml | 2 +- trunk/tools/daemon.pl | 36 ++++++++++++++++++++++++--------- 5 files changed, 71 insertions(+), 19 deletions(-) diff --git a/trunk/download.pl b/trunk/download.pl index a3a7453..e0bf952 100644 --- a/trunk/download.pl +++ b/trunk/download.pl @@ -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 ; + + $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 diff --git a/trunk/functions.pl b/trunk/functions.pl index 5ca47bf..42b3b62 100644 --- a/trunk/functions.pl +++ b/trunk/functions.pl @@ -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'}; diff --git a/trunk/locale/en-us.xml b/trunk/locale/en-us.xml index 72b59bc..c6263a0 100755 --- a/trunk/locale/en-us.xml +++ b/trunk/locale/en-us.xml @@ -27,7 +27,7 @@ Find Instant Access - Avanced Search + Advanced Search latest additions most downloaded diff --git a/trunk/site/main.xml b/trunk/site/main.xml index 73f05a2..176e5c0 100755 --- a/trunk/site/main.xml +++ b/trunk/site/main.xml @@ -1,4 +1,4 @@ - + diff --git a/trunk/tools/daemon.pl b/trunk/tools/daemon.pl index 561cd90..1cbe39c 100755 --- a/trunk/tools/daemon.pl +++ b/trunk/tools/daemon.pl @@ -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";