Browse Source

Ticket #1852 - MP4 HD should be generated when it's necessary.

AntonLV 7 years ago
parent
commit
5935459c69

+ 2 - 2
inc/classes/BxDolTranscoderVideo.php

@@ -228,7 +228,7 @@ class BxDolTranscoderVideo extends BxDolTranscoder implements iBxDolFactoryObjec
      * @param $sFile path to the video file
      * @return array where 'w' key is width and 'h' key is height
      */
-    protected function _getVideoSize ($sFile)
+    public function getVideoSize ($sFile)
     {
         $sFileOut = $this->getTmpFilename('.jpg');
 
@@ -272,7 +272,7 @@ class BxDolTranscoderVideo extends BxDolTranscoder implements iBxDolFactoryObjec
             $aParams['h'] = '360';
 
         $fRatio = 16/9;
-        $aSize = $this->_getVideoSize($sFile);
+        $aSize = $this->getVideoSize($sFile);
         if ($aSize)
             $fRatio = $aSize['w'] / $aSize['h'];
 

+ 9 - 1
modules/base/general/classes/BxBaseModGeneralTemplate.php

@@ -283,6 +283,14 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
                 ),
             );
 
+            $sVideoUrlHd = '';
+            if($isVideo) {
+                $sVideoUrl = $oStorage->getFileUrlById($a['id']);
+                $aVideoSize = $aTranscodersVideo['mp4_hd']->getVideoSize($sVideoUrl);
+                if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+                    $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($a['id']);
+            }
+
             // videos are displayed inline
             $a['bx_if:video'] = array (
                 'condition' => $isVideo,
@@ -290,7 +298,7 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
                     'video' => $isVideo && $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
                         $aTranscodersVideo['poster']->getFileUrl($a['id']), 
                         $aTranscodersVideo['mp4']->getFileUrl($a['id']), 
-                        $aTranscodersVideo['mp4_hd']->getFileUrl($a['id']),
+                        $sVideoUrlHd,
                         false, ''
                     ) : '',
                 ),

+ 1 - 0
modules/base/general/template/css/main.css

@@ -109,6 +109,7 @@ div.bx-base-general-breadcrumb i {
 }
 .bx-base-general-attachment {
     margin:1px;
+    text-align: center;
 }
 .bx-base-general-attachments .bx-base-general-attachment
 .bx-base-general-attachments .bx-base-general-attachment img,

+ 10 - 2
modules/base/text/classes/BxBaseModTextModule.php

@@ -396,13 +396,21 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
             return array();
 
         $aResults = array();
-        foreach ($aGhostFiles as $k => $a) 
+        foreach ($aGhostFiles as $k => $a) {
+            $sVideoUrl = $oStorage->getFileUrlById($a['id']);
+            $aVideoSize = $oTcMp4Hd->getVideoSize($sVideoUrl);
+
+            $sVideoUrlHd = '';
+            if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+                $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
+
             $aResults[$a['id']] = array(
                 'id' => $a['id'],
                 'src_poster' => $oTcPoster->getFileUrl($a['id']),
                 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
-                'src_mp4_hd' => $oTcMp4Hd->getFileUrl($a['id']),
+                'src_mp4_hd' => $sVideoUrlHd,
             );
+        }
 
         return $aResults;
     }

+ 8 - 1
modules/boonex/albums/classes/BxAlbumsModule.php

@@ -715,11 +715,18 @@ class BxAlbumsModule extends BxBaseModTextModule
             if(!$bVideo)
                 continue;
 
+            $sVideoUrl = $oStorage->getFileUrlById($aMedia['file_id']);
+            $aVideoSize = $oTcMp4Hd->getVideoSize($sVideoUrl);
+
+            $sVideoUrlHd = '';
+            if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+                $sVideoUrlHd = $oTcMp4Hd->getFileUrl($aMedia['file_id']);
+
             $aOutput[$aMedia['id']] = array(
                 'id' => $aMedia['id'],
                 'src_poster' => $oTcPoster->getFileUrl($aMedia['file_id']),
                 'src_mp4' => $oTcMp4->getFileUrl($aMedia['file_id']),
-                'src_mp4_hd' => $oTcMp4Hd->getFileUrl($aMedia['file_id']),
+                'src_mp4_hd' => $sVideoUrlHd,
             );
         }
 

+ 9 - 3
modules/boonex/albums/classes/BxAlbumsTemplate.php

@@ -273,7 +273,14 @@ class BxAlbumsTemplate extends BxBaseModTextTemplate
 
             $iVideoDuration = $oModule->getMediaDuration($aFileInfo);
             $sVideoDuration = _t_format_duration($iVideoDuration);
-            
+
+            $sVideoUrl = $oStorage->getFileUrlById($aMediaInfo['file_id']);
+            $aVideoSize = $aTranscodersVideo['mp4_hd']->getVideoSize($sVideoUrl);
+
+            $sVideoUrlHd = '';
+            if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+                $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($aMediaInfo['file_id']);
+
             $aTmplVarsVideo = array (
                 'title_attr' => $sMediaTitleAttr,
                 'title' => $sMediaTitle,
@@ -282,8 +289,7 @@ class BxAlbumsTemplate extends BxBaseModTextTemplate
                 'video' => $isVideo && $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
                     $aTranscodersVideo['poster']->getFileUrl($aMediaInfo['file_id']), 
                     $aTranscodersVideo['mp4']->getFileUrl($aMediaInfo['file_id']), 
-                    $aTranscodersVideo['mp4_hd']->getFileUrl($aMediaInfo['file_id']),
-                    $mixedAttrs, 'max-height:' . $CNF['OBJECT_VIDEO_TRANSCODER_HEIGHT']
+                    $sVideoUrlHd, $mixedAttrs, 'max-height:' . $CNF['OBJECT_VIDEO_TRANSCODER_HEIGHT']
                 ) : '',
                 'duration' => $sVideoDuration,
                 'bx_if:show_duration' => array(

+ 1 - 1
modules/boonex/albums/install/sql/install.sql

@@ -318,7 +318,7 @@ INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_par
 ('bx_albums_video_poster_preview', 'Resize', 'a:3:{s:1:"w";s:3:"300";s:1:"h";s:3:"300";s:13:"square_resize";s:1:"1";}', 10),
 ('bx_albums_video_poster_big', 'Poster', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_albums_video_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"mp4";}', 0),
-('bx_albums_video_mp4_hd', 'Mp4', 'a:2:{s:1:"h";s:3:"720";s:10:"force_type";s:3:"mp4";}', 0);
+('bx_albums_video_mp4_hd', 'Mp4', 'a:3:{s:1:"h";s:3:"720";s:13:"video_bitrate";s:4:"1536";s:10:"force_type";s:3:"mp4";}', 0);
 
 
 -- FORMS

+ 1 - 1
modules/boonex/directory/install/sql/install.sql

@@ -461,7 +461,7 @@ INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_par
 ('bx_directory_videos_poster_preview', 'Poster', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_directory_videos_poster', 'Poster', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_directory_videos_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"mp4";}', 0),
-('bx_directory_videos_mp4_hd', 'Mp4', 'a:2:{s:1:"h";s:3:"720";s:10:"force_type";s:4:"mp4";}', 0),
+('bx_directory_videos_mp4_hd', 'Mp4', 'a:3:{s:1:"h";s:3:"720";s:13:"video_bitrate";s:4:"1536";s:10:"force_type";s:3:"mp4";}', 0),
 
 ('bx_directory_preview_files', 'Resize', 'a:3:{s:1:"w";s:3:"300";s:1:"h";s:3:"200";s:11:"crop_resize";s:1:"1";}', '0'),
 ('bx_directory_gallery_files', 'Resize', 'a:1:{s:1:"w";s:3:"500";}', '0');

+ 1 - 1
modules/boonex/posts/install/sql/install.sql

@@ -349,7 +349,7 @@ INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_par
 ('bx_posts_videos_poster_preview', 'Poster', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_posts_videos_poster', 'Poster', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_posts_videos_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"mp4";}', 0),
-('bx_posts_videos_mp4_hd', 'Mp4', 'a:2:{s:1:"h";s:3:"720";s:10:"force_type";s:3:"mp4";}', 0),
+('bx_posts_videos_mp4_hd', 'Mp4', 'a:3:{s:1:"h";s:3:"720";s:13:"video_bitrate";s:4:"1536";s:10:"force_type";s:3:"mp4";}', 0),
 
 ('bx_posts_preview_files', 'Resize', 'a:3:{s:1:"w";s:3:"300";s:1:"h";s:3:"200";s:11:"crop_resize";s:1:"1";}', '0'),
 ('bx_posts_gallery_files', 'Resize', 'a:1:{s:1:"w";s:3:"500";}', '0');

+ 10 - 1
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -2084,16 +2084,25 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
                 $aVideos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
                 if(!empty($aVideos) && is_array($aVideos)) {
+                    $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_videos'));
+
                     $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
                     $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
                     $oTranscoderMp4Hd = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4_hd'));
 
                     foreach($aVideos as $iVideoId) {
+                        $sVideoUrl = $oStorage->getFileUrlById($iVideoId);
+                        $aVideoSize = $oTranscoderMp4Hd->getVideoSize($sVideoUrl);
+
+                        $sVideoUrlHd = '';
+                        if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+                            $sVideoUrlHd = $oTranscoderMp4Hd->getFileUrl($iVideoId);
+
                         $aResult['content']['videos_attach'][$iVideoId] = array(
                             'id' => $iVideoId,
                             'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
                             'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
-                            'src_mp4_hd' => $oTranscoderMp4Hd->getFileUrl($iVideoId),
+                            'src_mp4_hd' => $sVideoUrlHd,
                         );
                     }
                 }

+ 1 - 1
modules/boonex/timeline/install/sql/install.sql

@@ -328,7 +328,7 @@ INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_par
 
 ('bx_timeline_videos_poster', 'Poster', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_timeline_videos_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"318";s:10:"force_type";s:3:"mp4";}', 0),
-('bx_timeline_videos_mp4_hd', 'Mp4', 'a:2:{s:1:"h";s:3:"720";s:10:"force_type";s:3:"mp4";}', 0);
+('bx_timeline_videos_mp4_hd', 'Mp4', 'a:3:{s:1:"h";s:3:"720";s:13:"video_bitrate";s:4:"1536";s:10:"force_type";s:3:"mp4";}', 0);
 
 
 -- Forms -> Post

+ 12 - 3
modules/boonex/videos/classes/BxVideosModule.php

@@ -101,8 +101,10 @@ class BxVideosModule extends BxBaseModTextModule
         if(empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
             return array();
 
+        $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
+
         $iFile = (int)$aContentInfo[$CNF['FIELD_VIDEO']];
-        $aFile = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS'])->getFile($iFile);
+        $aFile = $oStorage->getFile($iFile);
         if(empty($aFile) || !is_array($aFile) || strncmp('video/', $aFile['mime_type'], 6) !== 0)
             return array();
 
@@ -113,18 +115,25 @@ class BxVideosModule extends BxBaseModTextModule
         if(!($oTcvPoster || $oTciPoster) || !$oTcvMp4 || !$oTcvMp4Hd)
             return array();
 
-		$sPosterSrc = !empty($CNF['FIELD_POSTER']) ? $CNF['FIELD_POSTER'] : $CNF['FIELD_THUMB'];
+        $sPosterSrc = !empty($CNF['FIELD_POSTER']) ? $CNF['FIELD_POSTER'] : $CNF['FIELD_THUMB'];
         if(!empty($sPosterSrc) && !empty($aContentInfo[$sPosterSrc]) && $oTciPoster)
             $sPoster = $oTciPoster->getFileUrl($aContentInfo[$sPosterSrc]);
         else 
             $sPoster = $oTcvPoster->getFileUrl($iFile);
 
+        $sVideoUrl = $oStorage->getFileUrlById($iFile);
+        $aVideoSize = $oTcvMp4Hd->getVideoSize($sVideoUrl);
+
+        $sVideoUrlHd = '';
+        if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+            $sVideoUrlHd = $oTcvMp4Hd->getFileUrl($iFile);
+
         return array(
             $iFile => array(
             	'id' => $iFile,
             	'src_poster' => $sPoster, 
             	'src_mp4' => $oTcvMp4->getFileUrl($iFile), 
-            	'src_mp4_hd' => $oTcvMp4Hd->getFileUrl($iFile)
+            	'src_mp4_hd' => $sVideoUrlHd
             )
         );
     }

+ 8 - 2
modules/boonex/videos/classes/BxVideosTemplate.php

@@ -100,13 +100,19 @@ class BxVideosTemplate extends BxBaseModTextTemplate
         else 
             $sPoster = $aTranscodersVideo['poster']->getFileUrl($iFile);
 
+        $sVideoUrl = $oStorage->getFileUrlById($iFile);
+        $aVideoSize = $aTranscodersVideo['mp4_hd']->getVideoSize($sVideoUrl);
+
+        $sVideoUrlHd = '';
+        if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] > 720)
+            $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($iFile);
+
         return array(
             'poster_url' => $aTranscodersVideo['poster']->getFileUrl($iFile),
             'player' => BxTemplFunctions::getInstance()->videoPlayer(
                 $sPoster, 
                 $aTranscodersVideo['mp4']->getFileUrl($iFile), 
-                $aTranscodersVideo['mp4_hd']->getFileUrl($iFile),
-                false, 'max-height:' . $CNF['OBJECT_VIDEO_TRANSCODER_HEIGHT']
+                $sVideoUrlHd, false, 'max-height:' . $CNF['OBJECT_VIDEO_TRANSCODER_HEIGHT']
             )
         );
     }

+ 1 - 1
modules/boonex/videos/install/sql/install.sql

@@ -251,7 +251,7 @@ INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_par
 ('bx_videos_video_poster_gallery', 'Poster', 'a:2:{s:1:"w";s:3:"500";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_videos_video_poster_cover', 'Poster', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"jpg";}', 0),
 ('bx_videos_video_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"mp4";}', 0),
-('bx_videos_video_mp4_hd', 'Mp4', 'a:2:{s:1:"h";s:3:"720";s:10:"force_type";s:3:"mp4";}', 0);
+('bx_videos_video_mp4_hd', 'Mp4', 'a:3:{s:1:"h";s:3:"720";s:13:"video_bitrate";s:4:"1536";s:10:"force_type";s:3:"mp4";}', 0);
 
 
 -- FORMS