liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file mime.video.php

Documentation is available at mime.video.php

  1. <?php
  2. /**
  3.  * @version        $Header$
  4.  *
  5.  * @author        xing  <xing@synapse.plus.com>
  6.  * @version        $Revision$
  7.  *  created        Thursday May 08, 2008
  8.  * @package        liberty
  9.  * @subpackage    liberty_mime_handler
  10.  ***/
  11.  
  12. /**
  13.  * setup
  14.  */
  15. global $gLibertySystem;
  16.  
  17. /**
  18.  *  This is the name of the plugin - max char length is 16
  19.  * As a naming convention, the liberty mime handler definition should start with:
  20.  * PLUGIN_MIME_GUID_
  21.  */
  22. define'PLUGIN_MIME_GUID_VIDEO''mimevideo' );
  23.  
  24. $pluginParams array (
  25.     // Set of functions and what they are called in this paricular plugin
  26.     // Use the GUID as your namespace
  27.     'preload_function'    => 'mime_video_preload',
  28.     'verify_function'     => 'mime_default_verify',
  29.     'store_function'      => 'mime_video_store',
  30.     'update_function'     => 'mime_video_update',
  31.     'load_function'       => 'mime_video_load',
  32.     'download_function'   => 'mime_default_download',
  33.     'expunge_function'    => 'mime_default_expunge',
  34.     // Brief description of what the plugin does
  35.     'title'               => 'Convert Video to Flash Video',
  36.     'description'         => 'This plugin will use ffmpeg to convert any compatible uploaded video to flash video. It will also make the video available for viewing if you have flash installed. Please consult the README on how to use this plugin.',
  37.     // Templates to display the files
  38.     'view_tpl'            => 'bitpackage:liberty/mime/video/view.tpl',
  39.     'inline_tpl'          => 'bitpackage:liberty/mime/video/inline.tpl',
  40.     'storage_tpl'         => 'bitpackage:liberty/mime/video/storage.tpl',
  41.     'attachment_tpl'      => 'bitpackage:liberty/mime/video/attachment.tpl',
  42.     'edit_tpl'            => 'bitpackage:liberty/mime/video/edit.tpl',
  43.     // url to page with options for this plugin
  44.     'plugin_settings_url' => LIBERTY_PKG_URL.'admin/plugins/mime_video.php',
  45.     // This should be the same for all mime plugins
  46.     'plugin_type'         => MIME_PLUGIN,
  47.     // Set this to TRUE if you want the plugin active right after installation
  48.     'auto_activate'       => FALSE,
  49.     // Help page on bitweaver.org
  50.     'help_page'           => 'LibertyMime+Video+Plugin',
  51.     // this should pick up all videos
  52.     'mimetypes'           => array(
  53.         '#video/.*#i',
  54.     ),
  55. );
  56. $gLibertySystem->registerPluginPLUGIN_MIME_GUID_VIDEO$pluginParams );
  57.  
  58. /**
  59.  * mime_video_preload This function is loaded on every page load before anything happens and is used to load required scripts.
  60.  *
  61.  * @access public
  62.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  63.  */
  64. function mime_video_preload({
  65.     global $gBitThemes;
  66.     $gBitThemes->loadJavascriptUTIL_PKG_PATH."javascript/flv_player/swfobject.js"FALSE25 );
  67. }
  68.  
  69. /**
  70.  * Store the data in the database
  71.  *
  72.  * @param array $pStoreRow File data needed to store details in the database - sanitised and generated in the verify function
  73.  * @access public
  74.  * @return TRUE on success, FALSE on failure - $pStoreRow['errors'] will contain reason
  75.  */
  76. function mime_video_store&$pStoreRow {
  77.     global $gBitSystem;
  78.  
  79.     // this will set the correct pluign guid, even if we let default handle the store process
  80.     $pStoreRow['attachment_plugin_guid'PLUGIN_MIME_GUID_VIDEO;
  81.  
  82.     // if storing works, we process the video
  83.     if$ret mime_default_store$pStoreRow )) {
  84.         if!mime_video_converter$pStoreRow )) {
  85.             $pStoreRow['errors'$pStoreRow['log'];
  86.             $ret FALSE;
  87.         }
  88.     }
  89.     return $ret;
  90. }
  91.  
  92. /**
  93.  * mime_video_update
  94.  *
  95.  * @param array $pStoreRow 
  96.  * @access public
  97.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  98.  */
  99. function mime_video_update&$pStoreRow$pParams NULL {
  100.     $ret FALSE;
  101.     ifBitBase::verifyId$pStoreRow['attachment_id')) {
  102.         $pStoreRow['log'array();
  103.  
  104.         // set the correct pluign guid, even if we let default handle the store process
  105.         $pStoreRow['attachment_plugin_guid'PLUGIN_MIME_GUID_VIDEO;
  106.         // remove the entire directory
  107.         $pStoreRow['unlink_dir'TRUE;
  108.  
  109.         // if storing works, we process the video
  110.         if!empty$pStoreRow['upload'&& $ret mime_default_update$pStoreRow )) {
  111.             if!mime_video_converter$pStoreRow )) {
  112.                 // if it all goes tits up, we'll know why
  113.                 $pStoreRow['errors'$pStoreRow['log'];
  114.                 $ret FALSE;
  115.             }
  116.         }
  117.  
  118.         // if there was no upload we'll process the file parameters
  119.         ifempty$pStoreRow['upload'&& isset$pParams['meta']['aspect')) {
  120.             // set aspect NULL that it's removed from the database
  121.             ifempty$pParams['meta']['aspect')) {
  122.                 $pParams['meta']['aspect'NULL;
  123.             }
  124.  
  125.             // we store the custom aspect ratio as a preference which we will use to override the original one
  126.             if!LibertyMime::storeAttachmentPreference$pStoreRow['attachment_id']'aspect'$pParams['meta']['aspect')) {
  127.                 $log['store_meta'"There was a problem storing the preference in the database";
  128.             }
  129.  
  130.             ifempty$log )) {
  131.                 $ret TRUE;
  132.             else {
  133.                 $pStoreRow['errors'$log;
  134.             }
  135.         }
  136.     }
  137.     return $ret;
  138. }
  139.  
  140. /**
  141.  * Load file data from the database
  142.  *
  143.  * @param array $pFileHash Contains all file information
  144.  * @param array $pPrefs Attachment preferences taken liberty_attachment_prefs
  145.  * @param array $pParams Parameters for loading the plugin - e.g.: might contain values from the view page
  146.  * @access public
  147.  * @return TRUE on success, FALSE on failure - ['errors'] will contain reason for failure
  148.  */
  149. function mime_video_load$pFileHash&$pPrefs$pParams NULL {
  150.     global $gLibertySystem$gBitThemes;
  151.     if$ret mime_default_load$pFileHash$pParams )) {
  152.         // check for status of conversion
  153.         if!empty$ret['source_file')) {
  154.             $source_path STORAGE_PKG_PATH.dirname$ret['source_file').'/';
  155.             ifis_file$source_path.'error' )) {
  156.                 $ret['status']['error'TRUE;
  157.             elseifis_file$source_path.'processing' )) {
  158.                 $ret['status']['processing'TRUE;
  159.             elseifis_file$source_path.'flick.flv' )) {
  160.                 $ret['media_url'storage_path_to_urldirname$ret['source_file').'/flick.flv' );
  161.             elseifis_file$source_path.'flick.mp4' )) {
  162.                 $ret['media_url'storage_path_to_urldirname$ret['source_file').'/flick.mp4' );
  163.             }
  164.         }
  165.  
  166.         // now that we have the original width and height, we can get the displayed values
  167.         $ret['meta'array_mergeLibertyMime::getMetaData$pFileHash['attachment_id']"Video" )$pPrefs );
  168.         mime_video_calculate_videosize$ret['meta']$pParams );
  169.     }
  170.     return $ret;
  171. }
  172.  
  173. /**
  174.  * This function will add an entry to the process queue for the cron job to take care of
  175.  *
  176.  * @param array $pContentId 
  177.  * @access public
  178.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  179.  */
  180. function mime_video_add_process$pStoreRow {
  181.     global $gBitSystem;
  182.     $ret FALSE;
  183.     if@BitBase::verifyId$pStoreRow['content_id')) {
  184.         $query "
  185.             UPDATE `".BIT_DB_PREFIX."liberty_process_queue`
  186.             SET `process_status`=?
  187.             WHERE `content_id`=? AND `process_status`=?";
  188.         $gBitSystem->mDb->query$queryarray'defunkt'$pStoreRow['content_id']'pending' ));
  189.  
  190.         $storeHash array (
  191.             'content_id'           => $pStoreRow['content_id'],
  192.             'queue_date'           => $gBitSystem->getUTCTime(),
  193.             'process_status'       => 'pending',
  194.             'processor'            => dirname__FILE__ ).'/mime.video.php',
  195.             'processor_parameters' => mime_video_converter$pStoreRowTRUE ),
  196.         );
  197.         $gBitSystem->mDb->associateInsertBIT_DB_PREFIX."liberty_process_queue"$storeHash );
  198.         $ret TRUE;
  199.     }
  200.     return $ret;
  201. }
  202.  
  203. /**
  204.  * Convert a stored video file to flashvideo
  205.  *
  206.  * @param array $pParamHash 
  207.  * @access public
  208.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  209.  */
  210. function mime_video_converter&$pParamHash$pOnlyGetParameters FALSE {
  211.     global $gBitSystem;
  212.  
  213.     // video conversion can take a while
  214.     ini_set"max_execution_time""1800" );
  215.  
  216.     $ret FALSE;
  217.  
  218.     if@BitBase::verifyId$pParamHash['attachment_id')) {
  219.         // we might have some attachment preferences set if this is an update
  220.         LibertyMime::expungeAttachmentPreferences$pParamHash['attachment_id');
  221.  
  222.         // these are set in the liberty plugin admin screen
  223.         $ffmpeg trim$gBitSystem->getConfig'ffmpeg_path'shell_exec'which ffmpeg' )));
  224.         $width  trim$gBitSystem->getConfig'mime_video_width'320 ));
  225.         $begin  date'U' );
  226.         $log    $actionLog array();
  227.  
  228.         if!is_executable$ffmpeg )) {
  229.             $log['time']     date'Y-M-d - H:i:s O' );
  230.             $log['duration'0;
  231.             $log['message']  'ERROR: ffmpeg does not seem to be available on your system at: '.$ffmpeg.' Please set the path to ffmpeg in the liberty plugin administration screen.';
  232.             $actionLog['log_message'"ERROR: ffmpeg does not seem to be available on your system at: '$ffmpeg' Please set the path to ffmpeg in the liberty plugin administration screen.";
  233.         else {
  234.             // this is the codec we'll use - currently this might be: flv, h264, h264-2pass
  235.             $codec $gBitSystem->getConfig"mime_video_video_codec""flv" );
  236.             $source STORAGE_PKG_PATH.$pParamHash['upload']['dest_branch'].$pParamHash['upload']['name'];
  237.             $destPath dirname$source );
  238.  
  239.             // set some default values if ffpeg-php isn't available or fails
  240.             $default['aspect']     3;
  241.             $default['video_width']  $width;
  242.             $default['video_height'round$width );
  243.             $default['size']       "{$default['video_width']}x{$default['video_height']}";
  244.             $default['offset']     '00:00:10';
  245.  
  246.             ifextension_loaded'ffmpeg' )) {
  247.                 // we silence these calls since they might spew errors
  248.                 $movie @new ffmpeg_movie$source );
  249.                 $info array(
  250.                     'vcodec'           => @$movie->getVideoCodec(),
  251.                     'duration'         => round@$movie->getDuration() ),
  252.                     'width'            => @$movie->getFrameWidth(),
  253.                     'height'           => @$movie->getFrameHeight(),
  254.                     'video_bitrate'    => @$movie->getVideoBitRate(),
  255.                     'acodec'           => @$movie->getAudioCodec(),
  256.                     'audio_bitrate'    => @$movie->getAudioBitRate(),
  257.                     'audio_samplerate' => @$movie->getAudioSampleRate(),
  258.                 );
  259.  
  260.                 // make sure audio sample rate is valid
  261.                 if!empty$info['audio_samplerate'&& !in_array$info['audio_samplerate']array110252205044100 ))) {
  262.                     unset$info['audio_samplerate');
  263.                 }
  264.             else {
  265.                 // alternative method using ffmpeg to fetch source dimensions
  266.                 $command "$ffmpeg -i ".escapeshellarg$source ).' 2>&1';
  267.                 exec$command$output$status );
  268.                 if!preg_match'/Stream #(?:[0-9\.]+)(?:.*)\: Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)/'implode'\n'$output )$matches )) {
  269.                     preg_match'/Could not find codec parameters \(Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)\)/'implode'\n'$output )$matches );
  270.                 }
  271.  
  272.                 if!empty$matches['width'&& !empty$matches['height')) {
  273.                     $info['width'$matches['width'];
  274.                     $info['height'$matches['height'];
  275.                 }
  276.             }
  277.  
  278.             // our player supports flv and h264 so we might as well use the default
  279.             if!$gBitSystem->isFeatureActive'mime_video_force_encode' && !empty$info )
  280.                 && (
  281.                     // accepted video + audio combinations that can be played by the video player directly
  282.                        $info['vcodec'== 'h264' && empty$info['acodec'|| $info['acodec'== 'mpeg4aac' || $info['acodec'== 'aac' ))
  283.                     || $info['vcodec'== 'flv'  && empty$info['acodec'|| $info['acodec'== 'mp3' ))
  284.                 )
  285.             {
  286.                 // work out what the target filename is
  287.                 $extension (( $info['vcodec'== "flv" "flv" "mp4" );
  288.                 $dest_file $destPath."/flick.$extension";
  289.  
  290.                 // if the video can be processed by ffmpeg-php, width and height are greater than 1
  291.                 if!empty$info['width'&& $info['width'{
  292.                     $info['aspect']   $info['width'$info['height'];
  293.                     $info['offset']   strftime"%T"round$info['duration'60 60 )));
  294.                 else {
  295.                     $info $default;
  296.                 }
  297.  
  298.                 // store prefs and create thumbnails
  299.                 LibertyMime::expungeMetaData$pParamHash['attachment_id');
  300.                 LibertyMime::storeMetaData$pParamHash['attachment_id']'Video'$info );
  301.                 mime_video_create_thumbnail$source$info['offset');
  302.                 if!is_file$dest_file && !link$source$dest_file )) {
  303.                     copy$source$dest_file );
  304.                 }
  305.                 mime_video_fix_streaming$dest_file );
  306.  
  307.                 $log['message''SUCCESS: Converted to flash video';
  308.                 $actionLog['log_message'"Video file was successfully uploaded and thumbnails extracted.";
  309.                 $ret TRUE;
  310.             else {
  311.                 // work out what the target filename is
  312.                 $extension (( $codec == "flv" "flv" "mp4" );
  313.                 $dest_file $destPath."/flick.$extension";
  314.  
  315.                 // if the video can be processed by ffmpeg-php, width and height are greater than 1
  316.                 if!empty$info['width'&& $info['width'{
  317.                     // reset some values to reduce video size
  318.                     if$info['width'$width {
  319.                         $width $info['width'];
  320.                     }
  321.  
  322.                     // here we calculate the size and aspect ratio of the output video
  323.                     $size_ratio         $width $info['width'];
  324.                     $info['aspect']     $info['width'$info['height'];
  325.                     $info['video_width']  $width;
  326.                     $info['video_height'round$size_ratio $info['height');
  327.                     // height of video needs to be an even number
  328.                     if$info['video_height'{
  329.                         $info['video_height']++;
  330.                     }
  331.                     $info['size']       "{$info['video_width']}x{$info['video_height']}";
  332.                 else {
  333.                     $info $default;
  334.                 }
  335.  
  336.                 // transfer settings to vars for easy manipulation for various APIs of ffmpeg
  337.                 $audio_bitrate    $gBitSystem->getConfig'mime_video_audio_bitrate'32000 1000 ).'kb';
  338.                 $audio_samplerate $gBitSystem->getConfig'mime_video_audio_samplerate'22050 );
  339.                 $video_bitrate    $gBitSystem->getConfig'mime_video_video_bitrate'160000 1000 ).'kb';
  340.                 $acodec_mp3       $gBitSystem->getConfig'ffmpeg_mp3_lib''libmp3lame' );
  341.                 $me_param         $gBitSystem->getConfig'ffmpeg_me_method''me' );
  342.  
  343.                 if$codec == "h264" {
  344.                     $parameters =
  345.                         " -i '$source'".
  346.                         // audio
  347.                         " -acodec libfaac".
  348.                         " -ab $audio_bitrate".
  349.                         " -ar $audio_samplerate".
  350.                         // video
  351.                         " -vcodec libx264".
  352.                         " -b $video_bitrate".
  353.                         " -bt $video_bitrate".
  354.                         " -s ".$info['size'].
  355.                         " -aspect ".$info['aspect'].
  356.                         " -flags +loop -cmp +chroma -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30".
  357.                         " -partitions +parti4x4+partp8x8+partb8x8 -$me_param epzs -subq 5 -trellis 1".
  358.                         // output
  359.                         " -y '$dest_file'";
  360.  
  361.                 elseif$codec == "h264-2pass" {
  362.                     // it is not possible to pass in the path for the x264 log file and it is always generated in the working dir.
  363.                     $cwd getcwd();
  364.                     chdirdirname$dest_file ));
  365.  
  366.                     $passlogfile dirname$dest_file )."/ffmpeg2pass";
  367.  
  368.                     // pass 1
  369.                     $parameters =
  370.                         " -i '$source'".
  371.                         // audio
  372.                         " -an".
  373.                         // video
  374.                         " -pass 1".
  375.                         " -passlogfile $passlogfile".
  376.                         " -vcodec libx264".
  377.                         " -b $video_bitrate".
  378.                         " -bt $video_bitrate".
  379.                         " -s ".$info['size'].
  380.                         " -aspect ".$info['aspect'].
  381.                         " -flags +loop -cmp +chroma -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bf 16 -maxrate 10M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30".
  382.                         " -partitions 0 -$me_param epzs -subq 1 -trellis 0".
  383.                         // output
  384.                         " -y '$dest_file'";
  385.  
  386.                     // pass 2
  387.                     $parameters2 =
  388.                         " -i '$source'".
  389.                         // audio
  390.                         " -acodec libfaac".
  391.                         " -ab $audio_bitrate".
  392.                         " -ar $audio_samplerate".
  393.                         // video
  394.                         " -pass 2".
  395.                         " -passlogfile $passlogfile".
  396.                         " -vcodec libx264".
  397.                         " -b $video_bitrate".
  398.                         " -bt $video_bitrate".
  399.                         " -s ".$info['size'].
  400.                         " -aspect ".$info['aspect'].
  401.                         " -flags +loop -cmp +chroma -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4".
  402.                         " -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -$me_param epzs -subq 7 -trellis 1 -refs 6 -bf 16 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1".
  403.                         // output
  404.                         " -y '$dest_file'";
  405.  
  406.                 else {
  407.                     $parameters =
  408.                         " -i '$source'".
  409.                         // audio
  410.                         " -acodec $acodec_mp3".
  411.                         " -ab $audio_bitrate".
  412.                         " -ar $audio_samplerate".
  413.                         // video
  414.                         " -f flv".
  415.                         " -b $video_bitrate".
  416.                         " -bt $video_bitrate".
  417.                         " -s ".$info['size'].
  418.                         " -aspect ".$info['aspect'].
  419.                         // output
  420.                         " -y '$dest_file'";
  421.                 }
  422.  
  423.                 if$pOnlyGetParameters {
  424.                     return $parameters;
  425.                 else {
  426.                     // we keep the output of this that we can store it to the error file if we need to do so
  427.                     $debug shell_exec"$ffmpeg $parameters 2>&1);
  428.                     if!empty$parameters2 )) {
  429.                         $debug .= shell_exec"$ffmpeg $parameters2 2>&1);
  430.                         // change back to whence we came
  431.                         chdir$cwd );
  432.                     }
  433.                 }
  434.  
  435.                 // make sure the conversion was successfull
  436.                 ifis_file$dest_file && filesize$dest_file 48 {
  437.                     mime_video_fix_streaming$dest_file );
  438.  
  439.                     // try to work out a reasonable timepoint where to extract a screenshot
  440.                     ifpreg_match'!Duration: ([\d:\.]*)!'$debug$time )) {
  441.                         list$h$m$s explode':'$time[1);
  442.                         $seconds round60 60 * (int)$h 60 * (int)$m + (float)$s );
  443.                         // we need to subract one hour from our time for strftime to return the correct value
  444.                         $info['offset'strftime"%T"round$seconds 60 60 )));
  445.                     else {
  446.                         $info['offset'"00:00:10";
  447.                     }
  448.                     // store some video specific settings
  449.                     LibertyMime::expungeMetaData$pParamHash['attachment_id');
  450.                     LibertyMime::storeMetaData$pParamHash['attachment_id']'Video'$info );
  451.  
  452.                     // since the flv conversion worked, we will create a preview screenshots to show.
  453.                     mime_video_create_thumbnail$dest_file$info['offset');
  454.  
  455.                     $log['message''SUCCESS: Converted to flash video';
  456.                     $actionLog['log_message'"Converted to flashvideo in ".date'U' $begin )." seconds";
  457.                     $ret TRUE;
  458.                 else {
  459.                     // remove unsuccessfully converted file
  460.                     @unlink$dest_file );
  461.                     $log['message'"ERROR: The video you uploaded could not be converted by ffmpeg.\nDEBUG OUTPUT:\n\n".$debug;
  462.                     $actionLog['log_message'"Video could not be converted to flashvideo. An error dump was saved to: ".$destPath.'/error';
  463.  
  464.                     // write error message to error file
  465.                     $h fopen$destPath."/error"'w' );
  466.                     fwrite$h"$ffmpeg $parameters\n\n$debug);
  467.                     fclose$h );
  468.                 }
  469.                 @unlink$destPath.'/processing' );
  470.             }
  471.         }
  472.  
  473.         $log['time']     date'd/M/Y:H:i:s O' );
  474.         $log['duration'date'U' $begin;
  475.  
  476.         // we'll insert some info into the database for reference
  477.         $actionLog['content_id'$pParamHash['content_id'];
  478.         $actionLog['title'"Uploaded file: {$pParamHash['upload']['name']} [Attchment ID: {$pParamHash['attachment_id']}]";
  479.  
  480.         // if this all goes tits up, we'll know why
  481.         $pParamHash['log'$log;
  482.  
  483.         // we'll add an entry in the action logs
  484.         LibertyContent::storeActionLogFromHasharray'action_log' => $actionLog ));
  485.  
  486.         // return the log
  487.         $pParamHash['log'$log;
  488.     }
  489.     return $ret;
  490. }
  491.  
  492. /**
  493.  * This function will create a thumbnail for a given video
  494.  *
  495.  * @param string $pFile path to video file
  496.  * @param numric $pOffset Offset in seconds to use to create thumbnail from
  497.  * @access public
  498.  * @return TRUE on success, FALSE on failure
  499.  */
  500. function mime_video_create_thumbnail$pFile$pOffset 60 {
  501.     global $gBitSystem;
  502.     $ret FALSE;
  503.     if!empty$pFile && is_file$pFile )) {
  504.         $destPath dirname$pFile );
  505.  
  506.         // try to use an app designed specifically to extract a thumbnail
  507.         ifshell_execshell_exec'which ffmpegthumbnailer' ).' -h' )) {
  508.             $thumbnailer trimshell_exec'which ffmpegthumbnailer' ));
  509.         elseifshell_execshell_exec'which ffmpegvideothumbnailer' ).' -h' )) {
  510.             $thumbnailer trimshell_exec'which ffmpegvideothumbnailer' ));
  511.         }
  512.  
  513.         if!empty$thumbnailer && is_executable$thumbnailer )) {
  514.             shell_exec"$thumbnailer -i '$pFile' -o '$destPath/thumb.jpg' -s 1024);
  515.         }
  516.  
  517.         ifis_file"$destPath/thumb.jpg&& filesize"$destPath/thumb.jpg{
  518.             $fileHash['type']            'image/jpg';
  519.             $fileHash['source_file']     "$destPath/thumb.jpg";
  520.             $fileHash['dest_branch']       str_replaceSTORAGE_PKG_PATH''"$destPath/);
  521.             liberty_generate_thumbnails$fileHash );
  522.             $ret TRUE;
  523.  
  524.             // remove temp file
  525.             @unlink"$destPath/thumb.jpg);
  526.         else {
  527.             // fall back to using ffmepg
  528.             $ffmpeg trim$gBitSystem->getConfig'ffmpeg_path'shell_exec'which ffmpeg' )));
  529.             shell_exec"$ffmpeg -i '$pFile' -an -ss $pOffset -t 00:00:01 -r 1 -y '$destPath/preview%d.jpg');
  530.             ifis_file"$destPath/preview1.jpg)) {
  531.                 $fileHash['type']            'image/jpg';
  532.                 $fileHash['source_file']     "$destPath/preview1.jpg";
  533.                 $fileHash['dest_branch']       str_replaceSTORAGE_PKG_PATH''"$destPath/);
  534.                 liberty_generate_thumbnails$fileHash );
  535.                 $ret TRUE;
  536.  
  537.                 // remove temp file
  538.                 @unlink"$destPath/preview1.jpg);
  539.             }
  540.         }
  541.     }
  542.     return $ret;
  543. }
  544.  
  545. /**
  546.  * mime_video_calculate_videosize Calculate the display video size
  547.  *
  548.  * @param array $pFileHash File information including attachment_id
  549.  * @param array $pCommonObject common object - calculations will be stored in $pCommonObject->mStoragePrefs
  550.  * @access public
  551.  * @return void 
  552.  */
  553. function mime_video_calculate_videosize&$pMetaData$pParams {
  554.     global $gBitSystem$gThumbSizes;
  555.  
  556.     // fetch default if width is missing
  557.     ifempty$pMetaData['width')) {
  558.         $pMetaData['width']  $gBitSystem->getConfig'mime_video_width'320 );
  559.     }
  560.  
  561.     // use aspect to calculate height since it might be different from original
  562.     $pMetaData['height'$pMetaData['width'!empty$pMetaData['aspect'$pMetaData['aspect'));
  563.  
  564.     // if we want to display a different size
  565.     if!empty$pParams['size'&& !empty$gThumbSizes[$pParams['size']]['width')) {
  566.         $new_width $gThumbSizes[$pParams['size']]['width'];
  567.     elseif$gBitSystem->isFeatureActive'mime_video_default_size' && !empty$gThumbSizes[$gBitSystem->getConfig'mime_video_default_size' )]['width')) {
  568.         $new_width $gThumbSizes[$gBitSystem->getConfig'mime_video_default_size' )]['width'];
  569.     }
  570.  
  571.     // if we want to change the video size
  572.     if!empty$new_width )) {
  573.         $ratio $pMetaData['width'$new_width;
  574.         $pMetaData['height'round$pMetaData['height'$ratio );
  575.  
  576.         // now that all calculations are done, we apply the width
  577.         $pMetaData['width']  $new_width;
  578.     }
  579. }
  580.  
  581. /**
  582.  * mime_video_fix_streaming will make sure the MOOV atom is at the beginning of the MP4 file to enable streaming
  583.  *
  584.  * @param array $pVideoFile 
  585.  * @access public
  586.  * @return string shell result on success, FALSE on failure
  587.  */
  588. function mime_video_fix_streaming$pVideoFile {
  589.     global $gBitSystem;
  590.     $ret FALSE;
  591.     ifpreg_match'#\.mp4$#'$pVideoFile && $gBitSystem->isFeatureActive'mp4box_path' )) {
  592.         $ret shell_exec$gBitSystem->getConfig'mp4box_path' )." -add $pVideoFile -new $pVideoFile);
  593.     }
  594.     return $ret;
  595. }
  596. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:08 +0000 by phpDocumentor 1.5.0-lsces