Skip to content

Commit

Permalink
code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anand989 committed Mar 15, 2015
1 parent 927fc94 commit fee0458
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 76 deletions.
14 changes: 14 additions & 0 deletions License.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2013-2015 Vyrazu Labs(http://www.vyrazu.com).

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of
the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
185 changes: 109 additions & 76 deletions library.media.php
Original file line number Diff line number Diff line change
@@ -1,136 +1,169 @@
<?php
/*
- Copyright 2013 Vyrazu Labs
- Subject to the terms and conditions of this License, each Contributor hereby grants to
- You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright
- license to reproduce, prepare Derivative Works of, publicly display, publicly perform,
- sublicense, and distribute the Work and such Derivative Works in Source or Object form.
* Copyright 2013 Vyrazu Labs
* Subject to the terms and conditions of this License, each Contributor hereby grants to
* You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright
* license to reproduce, prepare Derivative Works of, publicly display, publicly perform,
* sublicense, and distribute the Work and such Derivative Works in Source or Object form.
- We will be happy to get the attribution of the work we have provided.
* We will be happy to get the attribution of the work we have provided.
- Requires GD Module
- Requires ffmpeg Module
- Requires Imagick Module
* Requires GD Module
* Requires ffmpeg Module
* Requires Imagick Module
*/
class libraryMedia
{
/*
- variable to store the path the ffmpeg
* variable to store the path the ffmpeg
*/
private $ffmpeg;

function __construct()
{
//absolute path for the ffmpeg module
$this->ffmpeg = "/usr/local/bin/ffmpeg";
}
public $ffmpeg;

/*
- method of ffmpeg to take the snapshot
- Auth Singh
* method of ffmpeg to take the snapshot
* @var string
* @author Singh
*/
function getSnaps($moviePath,$no_snapshots,$video_h,$video_w,$output_path,$output_fileName)
public function getSnaps($moviePath,$no_snapshots,$video_h,$video_w,$output_path,$output_fileName)
{
//get the duration of the movie
$movie = new ffmpeg_movie($moviePath,0);
$movieDuration = $movie->getDuration();
//duration in second
//echo $movieDuration = ($movieDuration/60);

//get frame rate for the snapshots
$frameRate = ($no_snapshots)/$movieDuration ;
//$frameRate = round($frameRate,2);
$resolution = $video_h."x".$video_w;
exec("$this->ffmpeg -ss 00:00:20 -i $moviePath -r $frameRate -s $resolution -f image2 $output_path".$output_fileName."%05d.jpg " );
try{
exec("$this->ffmpeg -ss 00:00:20 -i $moviePath -r $frameRate -s $resolution -f image2 $output_path".$output_fileName."%05d.jpg " );
return 1;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

}

/*
- method to convert the video to a particular format
- @param $resolution example "320x240"
- Auth Singh
- @author Singh
*/
function convertVideo($inputFile,$outPath,$outputFormat,$outputFilename,$resolution)
public function convertVideo($inputFile,$outPath,$outputFormat,$outputFilename,$resolution)
{
exec("$this->ffmpeg -i $inputFile -c:v libx264 -c:a copy -s $resolution -f $outputFormat $outPath".$outputFilename );
return "1";
try{
exec("$this->ffmpeg -i $inputFile -c:v libx264 -c:a copy -s $resolution -f $outputFormat $outPath".$outputFilename );
return 1;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

/*
- method to slice the video
- @param time format tt:hh:ss
- @param resoltution format example 1200x768
- Auth Singh
* method to slice the video
* @author Singh
*/
function sliceVideo($inputFile,$startTime,$interval,$outPath,$outputFormat,$outputFilename,$resolution)
public function sliceVideo($inputFile,$startTime,$interval,$outPath,$outputFormat,$outputFilename,$resolution)
{
exec("$this->ffmpeg -ss $startTime -i $inputFile -c:v libx264 -c:a copy -s $resolution -async 1 -t $interval $outPath".$outputFilename);
try{
exec("$this->ffmpeg -ss $startTime -i $inputFile -c:v libx264 -c:a copy -s $resolution -async 1 -t $interval $outPath".$outputFilename);
return 1;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

/*
- method to resize the image
- @param absolute path of both input and output files
- Auth Singh
* method to resize the image
* @author Singh
*/
function resizeImage($inputFile,$imageWidth,$imageHeight,$outputFile)
public function resizeImage($inputFile,$imageWidth,$imageHeight,$outputFile)
{
$tempImage = new Imagick($inputFile);
$tempImage->resizeImage($imageWidth,$imageHeight,Imagick::FILTER_LANCZOS,1);
$tempImage->writeImage($outputFile);

$tempImage->destroy();
try {
$tempImage = new Imagick($inputFile);
$tempImage->resizeImage($imageWidth,$imageHeight,Imagick::FILTER_LANCZOS,1);
$tempImage->writeImage($outputFile);
$tempImage->destroy();
return 1;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

/*
- method to take the image and retutn height/width for aspect
- ratio calculation
- @param absolute path of both input
- Auth Singh
* method to take the image and retutn height/width for aspect
* ratio calculation
* @author Singh
*/
function getImageAspect($inputFile)
public function getImageAspect($inputFile)
{
$tempImage = new Imagick($inputFile) ;
$imageGeometry = $tempImage->getImageGeometry() ;
return $imageGeometry['height']/$imageGeometry['width'] ;
try {
$tempImage = new Imagick($inputFile) ;
$imageGeometry = $tempImage->getImageGeometry() ;
return $imageGeometry['height']/$imageGeometry['width'] ;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

/*
- method to take the video and return video duration
- @param absolute path of input video
- Auth Singh
* method to take the video and return video duration
* @author Singh
*/
function getVideoLength($inputVideo)
public function getVideoLength($inputVideo)
{
$movie = new ffmpeg_movie($inputVideo,0) ;
$movieDuration = $movie->getDuration() ;
return $movieDuration ;
try {
$movie = new ffmpeg_movie($inputVideo,0) ;
$movieDuration = $movie->getDuration() ;
return $movieDuration ;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

/*
- generate thumbnail from the video
- using ffmpeg
- time after a tumbnail is captured is 25 sec
- @param resolution format example 1200x900
- Auth Singh
* generate thumbnail from the video
* using ffmpeg
* time after a tumbnail is captured is 25 sec
* @author Singh
*/
function getThumbs($moviePath,$startTime,$resolution,$output_path,$output_fileName,$outputFormat)
public function getThumbs($moviePath,$startTime,$resolution,$output_path,$output_fileName,$outputFormat)
{
exec("$this->ffmpeg -ss $startTime -i $moviePath -s $resolution -frames:v 1 $output_path".$output_fileName.".".$outputFormat);
try {
exec("$this->ffmpeg -ss $startTime -i $moviePath -s $resolution -frames:v 1 $output_path".$output_fileName.".".$outputFormat);
return 1 ;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}

/*
- generate thumb for vids by merging two images
- the output image will contain a play sign
- Auth Singh
* generate thumb for vids by merging two images
* the output image will contain a play sign
* @author Singh
*/
function mergeImage($image1Path,$image1OutputPath,$image1Filename,$Format)
public function mergeImage($image1Path,$image1OutputPath,$image1Filename,$Format)
{
//path for the play sign
$path_play_sym = "" ;//put the path of the file such as a play symbol
$thumb = new Imagick($image1Path);
$play_sym = new Imagick($path_play_sym);

$thumb->compositeImage($play_sym , Imagick::COMPOSITE_DEFAULT, 0, 0 );

$thumb->writeImage($image1OutputPath.$image1Filename.".".$Format);
try {
//path for the play sign
$path_play_sym = "" ;//put the path of the file such as a play symbol
$thumb = new Imagick($image1Path);
$play_sym = new Imagick($path_play_sym);

$thumb->compositeImage($play_sym , Imagick::COMPOSITE_DEFAULT, 0, 0 );

$thumb->writeImage($image1OutputPath.$image1Filename.".".$Format);
return 1 ;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}

Expand Down

0 comments on commit fee0458

Please sign in to comment.