Permalink
Browse files

Fix the aspect ratio for the flowplayer

Fixes #9266.

Based on a user patch from Daniel Osborne <daniel@osborne.net.in> but redone
to pull the width and height markings more cleanly from the database, and to
use the custom aspect ratio from the db where appropriate.
  • Loading branch information...
1 parent 6ee5271 commit f33865d992e668f74d3d592b0d3917e96b1ff254 @Beirdo Beirdo committed May 27, 2011
Showing with 68 additions and 27 deletions.
  1. +45 −7 modules/stream/stream_flv.pl
  2. +23 −20 modules/tv/classes/Program.php
@@ -59,18 +59,56 @@
my ($abitrate) = $sh->fetchrow_array;
$sh->finish();
# auto-detect height based on aspect ratio
- $sh = $dbh->prepare('SELECT data FROM recordedmarkup WHERE chanid=? AND starttime=FROM_UNIXTIME(?) AND (type=30 OR type=31) AND mark=0 AND data IS NOT NULL ORDER BY type');
+ $sh = $dbh->prepare('SELECT data FROM recordedmarkup WHERE chanid=? ' .
+ 'AND starttime=FROM_UNIXTIME(?) AND type=30 ' .
+ 'AND data IS NOT NULL ORDER BY mark LIMIT 1');
$sh->execute($chanid,$starttime);
$x = $sh->fetchrow_array; # type = 30
+ $sh->finish();
+
+ $sh = $dbh->prepare('SELECT data FROM recordedmarkup WHERE chanid=? ' .
+ 'AND starttime=FROM_UNIXTIME(?) AND type=31 ' .
+ 'AND data IS NOT NULL ORDER BY mark LIMIT 1');
+ $sh->execute($chanid,$starttime);
$y = $sh->fetchrow_array if ($x); # type = 31
- $width = round_even($width);
- if ($x && $y) {
- $height = round_even($width * ($y/$x));
- } else {
- $height = round_even($width * 3/4);
- }
$sh->finish();
+ if (!$x || !$y || $x <= 720) { # <=720 means SD
+ $sh = $dbh->prepare('SELECT recordedmarkup.type, ' .
+ 'recordedmarkup.data '.
+ 'FROM recordedmarkup ' .
+ 'WHERE recordedmarkup.chanid = ? ' .
+ 'AND recordedmarkup.starttime = FROM_UNIXTIME(?) ' .
+ 'AND recordedmarkup.type IN (10, 11, 12, 13, 14) ' .
+ 'GROUP BY recordedmarkup.type ' .
+ 'ORDER BY SUM((SELECT IFNULL(rm.mark, recordedmarkup.mark) ' .
+ ' FROM recordedmarkup AS rm ' .
+ ' WHERE rm.chanid = recordedmarkup.chanid ' .
+ ' AND rm.starttime = recordedmarkup.starttime ' .
+ ' AND rm.type IN (10, 11, 12, 13, 14) ' .
+ ' AND rm.mark > recordedmarkup.mark ' .
+ ' ORDER BY rm.mark ASC LIMIT 1)- recordedmarkup.mark) DESC ' .
+ 'LIMIT 1');
+ $sh->execute($chanid,$starttime);
+ $aspect = $sh->fetchrow_hashref;
+ $sh->finish();
+
+ if( $aspect->{'type'} == 10 ) {
+ $x = $y = 1;
+ } elsif( $aspect->{'type'}== 11 ) {
+ $x = 4; $y = 3;
+ } elsif( $aspect->{'type'}== 12 ) {
+ $x = 16; $y = 9;
+ } elsif( $aspect->{'type'}== 13 ) {
+ $x = 2.21; $y = 1;
+ } elsif( $aspect->{'type'}== 14 ) {
+ $x = $aspect->{'data'}; $y = 10000;
+ } else {
+ $x = 4; $y = 3;
+ }
+ }
+ $height = round_even($width * ($y/$x));
+
$width = 320 unless ($width && $width > 1);
$height = 240 unless ($height && $height > 1);
$vbitrate = 256 unless ($vbitrate && $vbitrate > 1);
@@ -784,24 +784,28 @@ public function hasAlternativeFormat($format = 'mp4') {
public function getAspect() {
global $db;
- $aspect = $db->query_col('SELECT recordedmarkup.type
- FROM recordedmarkup
- WHERE recordedmarkup.chanid = ?
- AND recordedmarkup.starttime = FROM_UNIXTIME(?)
- AND recordedmarkup.type IN (10, 11, 12, 13, 14)
- GROUP BY recordedmarkup.type
- ORDER BY SUM((SELECT IFNULL(rm.mark, recordedmarkup.mark)
- FROM recordedmarkup AS rm
- WHERE rm.chanid = recordedmarkup.chanid
- AND rm.starttime = recordedmarkup.starttime
- AND rm.type IN (10, 11, 12, 13, 14)
- AND rm.mark > recordedmarkup.mark
- ORDER BY rm.mark ASC LIMIT 1)- recordedmarkup.mark) DESC
- LIMIT 1',
- $this->chanid,
- $this->recstartts
- );
- switch($aspect) {
+ $sh = $db->query('SELECT recordedmarkup.type,
+ recordedmarkup.data
+ FROM recordedmarkup
+ WHERE recordedmarkup.chanid = ?
+ AND recordedmarkup.starttime = FROM_UNIXTIME(?)
+ AND recordedmarkup.type IN (10, 11, 12, 13, 14)
+ GROUP BY recordedmarkup.type
+ ORDER BY SUM((SELECT IFNULL(rm.mark, recordedmarkup.mark)
+ FROM recordedmarkup AS rm
+ WHERE rm.chanid = recordedmarkup.chanid
+ AND rm.starttime = recordedmarkup.starttime
+ AND rm.type IN (10, 11, 12, 13, 14)
+ AND rm.mark > recordedmarkup.mark
+ ORDER BY rm.mark ASC LIMIT 1)- recordedmarkup.mark) DESC
+ LIMIT 1',
+ $this->chanid,
+ $this->recstartts
+ );
+ $row = $sh->fetch_assoc();
+ $sh->finish();
+
+ switch($row['aspect']) {
case 10:
return 1;
case 11:
@@ -811,10 +815,9 @@ public function getAspect() {
case 13:
return 2.21/1;
case 14:
- return 4/3;
+ return $row['data']/10000.0;
default:
return 4/3;
}
}
-
}

0 comments on commit f33865d

Please sign in to comment.