/** * Enter description here... * * @param unknown_type $original_file * @param unknown_type $new_file * @param unknown_type $c : config oblject * @return unknown */ public function movieToMp4H264($path_original, $path_new, $c) { ini_set("max_execution_time", 300000); $ffmpegpath = $c->ffmpeg_path; // Define standard video ratios, as used within the television and motion picture industries // To be consistent, round everything to 2-decimal places so all numbers are in the same format $broadcastTV = round(4 / 3, 2); // the aspect ratio is 4:3, which is 640/480; rounded to two decimals, this is 1.33 $widescreeenTV = round(16 / 9, 2); //the aspect ratio is 16:9, which is 640/360; rounded to two decimals, this is 1.78 $cinemaScope = 2.35; //the aspect ratio is 2.35:1, which is roughly 640/272 rounded to two decimal places // Let's set our absolute dimensions, as dicated by IPod and other external media players $maxWidth = 640; // per IPod specs (and other similar players), 640 is maximum width, period $wideMaxHeight = 360; //this number keeps the proper Widescreen aspect ratio when coupled with IPod's absolute maximum width of 640 $cinemaMaxHeight = 272; // this is the proper number for proper CinemaScope ratio coupled with IPod's absolute maximum width of 640 $standardMaxHeight = 480; // this is the standard height for broadcast ratio, and the largest video height Ipod can handle. $movie = new ffmpeg_movie($path_original); $fcodec = $movie->getVideoCodec(); // Now, check to see the size of the original video to make sure we're not enlarging something smaller than the max dimensions... $vidWith = $movie->getFrameWidth(); $vidHeight = $movie->getFrameHeight(); // Set up the encode variables that will actually be passed to the encoder. // Remember, our absolute maximum width is 640, no matter what the aspect ratio is if ($vidWidth >= $maxWidth) { $encodeWidth = $maxWidth; } else { $encodeWidth = $vidWidth; } // if ($encodeWidth == '') // $encodeWidth = $maxWidth; // Because video height is what determines the ratio, we have to compare actual video height to each of the three standard types // First, get the aspect ratio for the current movie - remember to round it so it's in two-decimal format like the other values $vidRatio = round($vidWidth / $vidHeight, 2); // Check to see if the video has a Widescreen or Cinematic ratio. If the video for some reason is neither Widescreen nor Cinematic, // then let's just use Standard ratio. $encodeHeight = $vidHeight; // Unless of course we have to adjust the height; see code below switch ($vidRatio) { case $vidRatio == $widescreenTV: if ($encodeHeight >= $wideMaxHeight) { $encodeHeight = $wideMaxHeight; } break; case $vidRatio == $cinemaScope: if ($encodeHeight >= $cinemaMaxHeight) { $encodeHeight = $cinemaMaxHeight; } break; default: // This is Broadcast TV, which is standard 640x480 ratio if ($encodeHeight >= $standardMaxHeight) { $encodeHeight = $standardMaxHeight; } } // Now, we can build the correct WxH (width x Height) ratio variable and pass this to the encode instructions. $encodeRatio = $encodeWidth . "x" . $encodeHeight; //echo $encodeRatio; exit(); if ($c->h264_quality == 'highest') { $cmd_mencoder = "{$ffmpegpath} -y -chromaoffset 0 -i {$path_original} -acodec libfaac -ab 150k -pass 2 -s 640x352 -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 {$path_new}"; //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 2 -s 640x480 -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new"; //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s ".$encodeRatio." -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new"; //$cmd_mencoder2 = "$ffmpegpath -y -chromaoffset 0 -i $path_original -acodec libfaac -ab 128k -pass 2 -s ".$encodeRatio." -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 $path_new"; //$cmd_mencoder3 = "/usr/local/bin/AtomicParsley $path_new --DeepScan --iPod-uuid 1200 --overWrite"; } if ($mp4_quality == 'default') { $cmd_mencoder = "{$ffmpegpath} -y -chromaoffset 0 -i {$path_original} -acodec libfaac -ab 128k -pass 2 -s 640x352 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 {$path_new}"; //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 2 -s 640x480 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new"; //$cmd_mencoder ="$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new"; //$cmd_mencoder2 ="$ffmpegpath -y -chromaoffset 0 -i $path_original -acodec libfaac -ab 128k -pass 2 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 $path_new"; //$cmd_mencoder3 ="/usr/local/bin/AtomicParsley $path_new --DeepScan --iPod-uuid 1200 --overWrite"; } if ($mp4_quality == 'lowest') { $cmd_mencoder = "{$ffmpegpath} -y -chromaoffset 0 -i {$path_original} -acodec libfaac -ab 128k -pass 1 -s 640x352 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 {$path_new}"; //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s 640x480 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new"; //$cmd_mencoder ="$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new"; //$cmd_mencoder2 ="$ffmpegpath -y -chromaoffset 0 -i $path_original -acodec libfaac -ab 128k -pass 2 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 $path_new"; //$cmd_mencoder3 ="/usr/local/bin/AtomicParsley $path_new --DeepScan --iPod-uuid 1200 --overWrite"; } return exec("{$cmd_mencoder} 2>&1"); }
/** * Completes track information from a given path using ffmpeg. * @param Track $track */ public function autocompleteTrack(Track $track) { if (!$track->getPath()) { throw new \BadMethodCallException('Input track has no path defined'); } $file = $track->getPath(); $movie = new \ffmpeg_movie($file, false); $finfo = new \finfo(); if (!$this->fileHasMediaContent($finfo, $file)) { throw new \InvalidArgumentException("This file has no video nor audio tracks"); } $only_audio = true; // General $track->setMimetype($finfo->file($file, FILEINFO_MIME_TYPE)); $track->setBitrate($movie->getBitRate()); $track->setDuration(ceil($movie->getDuration())); $track->setSize(filesize($file)); if ($movie->hasVideo()) { $only_audio = false; $track->setVcodec($movie->getVideoCodec()); $track->setFramerate($movie->getFrameRate()); $track->setWidth($movie->getFrameWidth()); $track->setHeight($movie->getFrameHeight()); } if ($movie->hasAudio()) { $track->setAcodec($movie->getAudioCodec()); $track->setChannels($movie->getAudioChannels()); } $track->setOnlyAudio($only_audio); }
public function getVideoSize($fileName) { $ffmpegInstance = new ffmpeg_movie($fileName); $video_size['width'] = $ffmpegInstance->getFrameWidth(); $video_size['height'] = $ffmpegInstance->getFrameHeight(); $video_size['duration'] = $ffmpegInstance->getDuration(); $video_size['frame_rate'] = $ffmpegInstance->getFrameRate(); $video_size['frame_count'] = $ffmpegInstance->getFrameCount(); return $video_size; }
function getVideoMetadata(&$form_values) { module_load_include('php', 'Fedora_Repository', 'mimetype'); global $base_url; $fileUrl = $form_values["ingest-file-location"]; $file_size = filesize($fileUrl); $file_md5 = md5_file($fileUrl); $file_path = $base_url . '/fedora/repository/' . $form_values['pid'] . '/FULL_SIZE'; $ffmpegInstance = new ffmpeg_movie($fileUrl); $form_values['vid_framerate'] = $ffmpegInstance->getFrameRate(); $form_values['vid_frameheight'] = $ffmpegInstance->getFrameHeight(); $form_values['vid_framewidth'] = $ffmpegInstance->getFrameWidth(); $form_values['vid_bitrate'] = $ffmpegInstance->getBitRate(); $form_values['vid_mime'] = mime_content_type($fileUrl); $form_values['vid_size'] = $file_size; $form_values['vid_md5'] = $file_md5; $form_values['vid_file'] = $file_path; }
function get_info($file) { if (!class_exists('ffmpeg_movie') or !($movie = new ffmpeg_movie($file))) { //ffmpeg extension required return false; } $duration = $movie->getDuration(); $width = $movie->getFrameWidth(); $height = $movie->getFrameHeight(); $framerate = $movie->getFrameRate(); $data = ''; if ($duration) { $data .= "Duration: {$duration}\n"; } if ($width and $height) { $data .= "Dimensions: {$width} x {$height} px\n"; } if ($framerate) { $data .= "Framerate: {$framerate} fps\n"; } return $data; }
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX; $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname; // load extension if (!extension_loaded($extension)) { dl($extension_soname); } // Set our source file $srcFile = $gdir . $filename; $destFile = $gdir . "tmp_" . substr($filename, 0, strrpos($filename, ".")) . ".flv"; $newFile = substr($filename, 0, strrpos($filename, ".")) . ".flv"; $thumbFile = $gdir . "tn_" . substr($filename, 0, strrpos($filename, ".")) . ".flv.jpg"; $ffmpegPath = "ffmpeg"; // Create our FFMPEG-PHP class $ffmpegObj = new ffmpeg_movie($srcFile); // Save our needed variables $srcWidth = $ffmpegObj->getFrameWidth(); $srcHeight = $ffmpegObj->getFrameHeight(); $srcFPS = $ffmpegObj->getFrameRate(); $srcAB = intval($ffmpegObj->getAudioBitRate() / 1000); $srcAR = $ffmpegObj->getAudioSampleRate(); // thumbnail $ff_frame = $ffmpegObj->getFrame(30); if ($ff_frame) { $ff_frame->resize($_SESSION['site_thumbwidth'], $_SESSION['site_thumbheight']); $gd_image = $ff_frame->toGDImage(); if ($gd_image) { //ha nincs konvertalas, akkor mas lez a file neve if (empty($_SESSION['site_gallery_is_convert'])) { $thumbFile = $gdir . $tn_name . ".jpg"; } imagejpeg($gd_image, $thumbFile);
function analyzeMediaFile(&$metaData, $filePath = NULL, $cachePath = NULL) { if (!isset($metaData->fileName) || !isset($metaData->fileType)) { throw new Exception("meta data invalid"); } $file = $filePath . DIRECTORY_SEPARATOR . $metaData->fileName; if (!is_file($file) || !is_readable($file)) { throw new Exception("file does not exist"); } if (!is_dir($cachePath)) { throw new Exception("cache dir does not exist"); } switch ($metaData->fileType) { case "video/quicktime": case "application/ogg": case "audio/mpeg": case "video/mp4": case "video/x-msvideo": case "video/ogg": case "video/webm": case "video/x-ms-asf": case "video/x-flv": case "audio/x-wav": case "application/octet-stream": if (isMediaFile($metaData, $filePath)) { $media = new ffmpeg_movie($file, FALSE); /**************************************************** * VIDEO ****************************************************/ if ($media->hasVideo()) { $metaData->video->codec = $media->getVideoCodec(); $metaData->video->width = $media->getFrameWidth(); $metaData->video->height = $media->getFrameHeight(); $metaData->video->bitrate = $media->getVideoBitRate(); $metaData->video->framerate = $media->getFrameRate(); $metaData->video->duration = $media->getDuration(); /* Video Still */ $stillFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png"; $fc = (int) ($media->getFrameCount() / 32); /* frame count is not necessarily reliable! */ foreach (array($fc, 100, 10, 1) as $fno) { if ($fno == 0) { continue; } $f = $media->getFrame($fno); if ($f !== FALSE) { imagepng($f->toGDImage(), $stillFile); $metaData->video->still = basename($stillFile); break; } } /* Video Thumbnails */ $thumbSizes = array(90, 180, 360); foreach ($thumbSizes as $tS) { $thumbFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png"; list($thumb_width, $thumb_height) = generateThumbnail($stillFile, $thumbFile, $tS); $metaData->video->thumbnail->{$tS}->file = basename($thumbFile); $metaData->video->thumbnail->{$tS}->width = $thumb_width; $metaData->video->thumbnail->{$tS}->height = $thumb_height; } /* Schedule for transcoding */ $transcodeSizes = array(360); $metaData->transcodeStatus = 'WAITING'; $metaData->transcodeProgress = 0; foreach ($transcodeSizes as $tS) { $transcodeFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".webm"; list($width, $height) = scaleVideo($media->getFrameWidth(), $media->getFrameHeight(), $tS); $metaData->video->transcode->{$tS}->file = basename($transcodeFile); $metaData->video->transcode->{$tS}->width = $width; $metaData->video->transcode->{$tS}->height = $height; } } /**************************************************** * AUDIO ****************************************************/ if ($media->hasAudio()) { $metaData->audio->codec = $media->getAudioCodec(); $metaData->audio->bitrate = $media->getAudioBitRate(); $metaData->audio->samplerate = $media->getAudioSampleRate(); $metaData->audio->duration = $media->getDuration(); $metaData->transcodeStatus = 'WAITING'; $metaData->transcodeProgress = 0; $transcodeFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".ogg"; $metaData->audio->transcode->file = basename($transcodeFile); } } else { /* No media? */ } break; case "image/jpeg": case "image/png": case "image/gif": case "image/bmp": list($width, $height) = getimagesize($file); $metaData->image->width = $width; $metaData->image->height = $height; $thumbFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png"; list($thumb_width, $thumb_height) = generateThumbnail($file, $thumbFile, 360); $metaData->image->thumbnail->{360}->file = basename($thumbFile); $metaData->image->thumbnail->{360}->width = $thumb_width; $metaData->image->thumbnail->{360}->height = $thumb_height; break; default: /* no idea about this file, let it go... */ } }
printf("<tr><td>title</td><td>%s<br/></td></tr>", $mov->getTitle()); printf("<tr><td>author</td><td>%s<br/></td></tr>", $mov->getAuthor()); printf("<tr><td>copyright</td><td>%s<br/></td></tr>", $mov->getCopyright()); printf("<tr><td>get bit rate</td><td>%d<br/></td></tr>", $mov->getBitRate()); printf("<tr><td>has audio</td><td>%s<br/></td></tr>", $mov->hasAudio() == 0 ? 'No' : 'Yes'); if ($mov->hasAudio()) { printf("<tr><td>get audio stream id</td><td>%s<br/></td></tr>", $mov->getAudioStreamId()); printf("<tr><td>get audio codec</td><td>%s<br/></td></tr>", $mov->getAudioCodec()); printf("<tr><td>get audio bit rate</td><td>%d<br/></td></tr>", $mov->getAudioBitRate()); printf("<tr><td>get audio sample rate</td><td>%d<br/></td></tr>", $mov->getAudioSampleRate()); printf("<tr><td>get audio channels</td><td>%s<br/></td></tr>", $mov->getAudioChannels()); } printf("<tr><td>has video</td><td>%s<br/></td></tr>", $mov->hasVideo() == 0 ? 'No' : 'Yes'); if ($mov->hasVideo()) { printf("<tr><td>frame height</td><td>%d pixels<br/></td></tr>", $mov->getFrameHeight()); printf("<tr><td>frame width</td><td>%d pixels<br/></td></tr>", $mov->getFrameWidth()); printf("<tr><td>get video stream id</td><td>%s<br/></td></tr>", $mov->getVideoStreamId()); printf("<tr><td>get video codec</td><td>%s<br/></td></tr>", $mov->getVideoCodec()); printf("<tr><td>get video bit rate</td><td>%d<br/></td></tr>", $mov->getVideoBitRate()); printf("<tr><td>get pixel format</td><td>%s<br/></td></tr>", $mov->getPixelFormat()); printf("<tr><td>get pixel aspect ratio</td><td>%s<br/></td></tr>", $mov->getPixelAspectRatio()); printf("<tr><td>get frame</td><td>%s<br/></td></tr>", is_object($mov->getFrame(10)) ? 'true' : 'false'); printf("<tr><td>get frame number</td><td>%d<br/></td></tr>", $mov->getFrameNumber()); $thumbpath = "{$i}.png"; if (make_test_thumbnail(rand(1, 100), $mov->getFilename(), $thumbpath)) { printf('<tr><td>Random Thumbnail</td><td><img alt="Test Image" src="%s"/></td></tr>', $thumbpath); } } echo "</table>"; echo "<p/><p/>"; $i++;
public function generateFFMPEG() { $ff = new ffmpeg_movie($this->pathname . $this->filename); if (!$ff) { $this->unknown = true; return false; } $this->info = array('width' => $ff->getFrameWidth(), 'height' => $ff->getFrameHeight(), 'duration' => $ff->getDuration(), 'mime' => $this->mime, 'size' => filesize($this->pathname . $this->filename)); if ($ff->getFrameCount() > 20) { $frame = $frame = $ff->getFrame(20); } else { $frame = $frame = $ff->getFrame($ff->getFrameCount() - 1); } $gd = $frame->toGDImage(); imagejpeg($gd, $this->pathcache . $this->getBaseName()); $this->mime = 'image/jpeg'; $this->type = array('video', 'jpeg'); $this->pathname = $this->pathcache; $this->filename = $this->getBaseName(); }
printf("title = %s\n", $mov->getTitle()); printf("author = %s\n", $mov->getAuthor()); printf("copyright = %s\n", $mov->getCopyright()); printf("get bit rate = %d\n", $mov->getBitRate()); printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes'); if ($mov->hasAudio()) { printf("get audio stream id= %s\n", $mov->getAudioStreamId()); printf("get audio codec = %s\n", $mov->getAudioCodec()); printf("get audio bit rate = %d\n", $mov->getAudioBitRate()); printf("get audio sample rate = %d \n", $mov->getAudioSampleRate()); printf("get audio channels = %s\n", $mov->getAudioChannels()); } printf("has video = %s\n", $mov->hasVideo() == 0 ? 'No' : 'Yes'); if ($mov->hasVideo()) { printf("frame height = %d pixels\n", $mov->getFrameHeight()); printf("frame width = %d pixels\n", $mov->getFrameWidth()); printf("get video stream id= %s\n", $mov->getVideoStreamId()); printf("get video codec = %s\n", $mov->getVideoCodec()); printf("get video bit rate = %d\n", $mov->getVideoBitRate()); printf("get pixel format = %s\n", $mov->getPixelFormat()); printf("get pixel aspect ratio = %s\n", $mov->getPixelAspectRatio()); $frame = $mov->getFrame(10); printf("get frame = %s\n", is_object($frame) ? 'true' : 'false'); printf(" get frame number = %d\n", $mov->getFrameNumber()); printf(" get frame width = %d\n", $frame->getWidth()); printf(" get frame height = %d\n", $frame->getHeight()); } echo "\n--------------------\n\n"; } if (php_sapi_name() != 'cli') { echo '</pre>';
?> ) </a> <h2>Please, find attached the Video file<br /><strong><?php echo basename($mediaAccess->basename, '.flv'); ?> <br /></strong> </h2> <p>Technical information</strong> : <strong><?php echo round($mediaAccess->getFFMEPGObject()->getDuration()); ?> s</strong> duration / <strong> <?php $video_source = getFtpMediasRoot() . $mediaAccess->srcname; $movie = new ffmpeg_movie($video_source); echo $movie->getFrameWidth(); ?> x <?php $video_source = getFtpMediasRoot() . $mediaAccess->srcname; $movie = new ffmpeg_movie($video_source); echo $movie->getFrameHeight(); ?> px</strong> source size / <strong> <?php echo strtolower(substr($mediaAccess->srcname, -3)); ?> </strong> file format</p> <div class="lineclear"><p class="hide"> </p></div> <p> </p> </div>
$ext = end($trozos); if ($ext == "iso" or $ext == "ISO") { shell_exec("mkdir {$tmp}{$pelnomf}"); shell_exec("7z x {$tmp}{$pelnomf}.{$ext} -o{$tmp}{$pelnomf}"); chmod("{$tmp}{$pelnomf}", 0777); $VOB = "/VIDEO_TS/VTS_01_[12345].VOB"; shell_exec("cat {$tmp}{$pelnomf}{$VOB} > {$tmp}{$pelnomf}.VOB"); shell_exec("ffmpeg -threads {$th} -i {$tmp}{$pelnomf}.VOB -vcodec libx264 -vb {$bit} -maxrate {$bit} -bufsize 1000k -s hd720 -acodec libfaac -ab {$bita} -ac 2 {$diref}{$pelnomf}.mp4"); shell_exec("rm -Rf {$tmp}{$pelnomf}"); shell_exec("rm -Rf {$tmp}{$pelnomf}.VOB"); } else { //Formatos tradicionales de video $pelif = "../files/{$files5}"; $varpel = new ffmpeg_movie($pelif); //obtener ancho y alto original del video $ancho = $varpel->getFrameWidth(); $alto = $varpel->getFrameHeight(); //Hz del audio $hz = $varpel->getAudioSampleRate(); //Framer por segundo $fps = $varpel->getFrameRate(); //Canales $canales = $varpel->getAudioChannels(); // Formula para convertir alto equivalente para ancho 720 $calcula = $HD * $alto / $ancho; if ($calcula % 2 == 0) { $altof = "{$calcula}"; } else { $altof = ++$calcula; } // Fin de Formula
public function getDetails() { $path = Yii::getPathOfAlias('application'); $file = $path . '/files/' . uid() . DS . $this->file; /* $command = '/usr/bin/ffmpeg -i ' . escapeshellarg($file) . ' 2>&1'; $dimensions = array('width'=>0,'height'=>0); exec($command, $output, $status); if(preg_match("/Duration: (?P<hour>[0-9]{2})\:(?P<minute>[0-9]{2})\:(?P<seconds>[0-9]{2})\.[0-9]{2}/",implode("\n",$output),$arr)) $dimensions['duration'] = $arr['hour']*3600 + $arr['minute']*60 + $arr['seconds']; else $dimensions['duration'] = 0; if (!preg_match('/Stream #(?:[0-9\.]+)(?:.*)\: Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)/', implode('\n', $output), $matches)) { preg_match('/Could not find codec parameters \(Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)\)/', implode('\n', $output), $matches); } */ if (class_exists('ffmpeg_movie')) { $movie = new ffmpeg_movie($file, false); if ($movie == NULL) { return NULL; } $dimensions['duration'] = $movie->getDuration(); $dimensions['width'] = $movie->getFrameWidth(); $dimensions['height'] = $movie->getFrameHeight(); } else { $dimensions['duration'] = 0; $dimensions['width'] = 640; $dimensions['height'] = 360; } /* if (!empty($matches['width']) && !empty($matches['height'])) { $dimensions['width'] = $matches['width']; $dimensions['height'] = $matches['height']; } */ return $dimensions; }
/** * Add a post */ public function iframe_add() { $this->setView('iframe_add.php'); @set_time_limit(0); $uploaded_files = array(); try { if (!isset(User_Model::$auth_data)) { throw new Exception(__('POST_ADD_ERROR_SESSION_EXPIRED')); } $is_student = isset(User_Model::$auth_data['student_number']); // Message $message = isset($_POST['message']) ? trim($_POST['message']) : ''; if ($message == '' || $message == __('PUBLISH_DEFAULT_MESSAGE')) { throw new Exception(__('POST_ADD_ERROR_NO_MESSAGE')); } $message = preg_replace('#\\n{2,}#', "\n\n", $message); // Category if (!isset($_POST['category']) || !ctype_digit($_POST['category'])) { throw new Exception(__('POST_ADD_ERROR_NO_CATEGORY')); } $category = (int) $_POST['category']; // Official post (in a group) $official = isset($_POST['official']); // Group $group = isset($_POST['group']) && ctype_digit($_POST['group']) ? (int) $_POST['group'] : 0; if ($group == 0) { $group = null; $official = false; } else { $groups_auth = Group_Model::getAuth(); if (isset($groups_auth[$group])) { if ($official && !$groups_auth[$group]['admin']) { throw new Exception(__('POST_ADD_ERROR_OFFICIAL')); } } else { throw new Exception(__('POST_ADD_ERROR_GROUP_NOT_FOUND')); } } // Private message $private = isset($_POST['private']); if ($private && !$is_student) { throw new Exception(__('POST_ADD_ERROR_PRIVATE')); } $attachments = array(); // Photos if (isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) { foreach ($_FILES['attachment_photo']['size'] as $size) { if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) { throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO)))); } } if ($filepaths = File::upload('attachment_photo')) { foreach ($filepaths as $filepath) { $uploaded_files[] = $filepath; } foreach ($filepaths as $i => $filepath) { $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : ''; try { $img = new Image(); $img->load($filepath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getWidth() > 800) { $img->setWidth(800, true); } $img->save($filepath); // Thumb $thumbpath = $filepath . '.thumb'; $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]); $img->setType(IMAGETYPE_JPEG); $img->save($thumbpath); unset($img); $attachments[] = array($filepath, $name, $thumbpath); $uploaded_files[] = $thumbpath; } catch (Exception $e) { throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT')); } } } } // Vidéos /* @uses PHPVideoToolkit : http://code.google.com/p/phpvideotoolkit/ * @requires ffmpeg, php5-ffmpeg */ if (isset($_FILES['attachment_video']) && is_array($_FILES['attachment_video']['name'])) { foreach ($_FILES['attachment_video']['size'] as $size) { if ($size > Config::UPLOAD_MAX_SIZE_VIDEO) { throw new Exception(__('POST_ADD_ERROR_VIDEO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_VIDEO)))); } } if ($filepaths = File::upload('attachment_video')) { foreach ($filepaths as $filepath) { $uploaded_files[] = $filepath; } foreach ($filepaths as $i => $filepath) { $name = isset($_FILES['attachment_video']['name'][$i]) ? $_FILES['attachment_video']['name'][$i] : ''; try { $video = new ffmpeg_movie($filepath, false); if (!$video->hasVideo()) { throw new Exception('No video stream found in the file'); } if (!$video->hasAudio()) { throw new Exception('No audio stream found in the file'); } } catch (Exception $e) { throw new Exception(__('POST_ADD_ERROR_VIDEO_FORMAT')); } // Video conversion try { $video_current_width = $video->getFrameWidth(); $video_width = min($video_current_width, Config::VIDEO_MAX_WIDTH); if ($video_width % 2 == 1) { // Even number required $video_width--; } $video_height = $video_width * $video->getFrameHeight() / $video_current_width; if ($video_height % 2 == 1) { // Even number required $video_height--; } // Extract thumb $video_thumb = $video->getFrame(round($video->getFrameCount() * 0.2)); unset($video); $video_thumb = $video_thumb->toGDImage(); $thumbpath = DATA_DIR . Config::DIR_DATA_TMP . File::getName($filepath) . '.thumb'; imagejpeg($video_thumb, $thumbpath, 95); unset($video_thumb); $img = new Image(); $img->load($thumbpath); $img->setWidth($video_width, true); $img->setType(IMAGETYPE_JPEG); $img->save($thumbpath); $uploaded_files[] = $thumbpath; unset($img); // Convert to FLV if (!preg_match('#\\.flv$#i', $filepath)) { $toolkit = new PHPVideoToolkit(); $toolkit->on_error_die = true; // Will throw exception on error $toolkit->setInputFile($filepath); $toolkit->setVideoOutputDimensions($video_width, $video_height); $toolkit->setFormatToFLV(Config::VIDEO_SAMPLING_RATE, Config::VIDEO_AUDIO_BIT_RATE); $toolkit->setOutput(DATA_DIR . Config::DIR_DATA_TMP, File::getName($filepath) . '.flv', PHPVideoToolkit::OVERWRITE_EXISTING); $toolkit->execute(false, false); // Multipass: false, Log: false File::delete($filepath); $filepath = $toolkit->getLastOutput(); $filepath = $filepath[0]; unset($toolkit); } $attachments[] = array($filepath, $name, $thumbpath); $uploaded_files[] = $filepath; } catch (Exception $e) { throw new Exception(__('POST_ADD_ERROR_VIDEO_CONVERT') . $e->getMessage()); } } } } // Audios if (isset($_FILES['attachment_audio']) && is_array($_FILES['attachment_audio']['name'])) { foreach ($_FILES['attachment_audio']['size'] as $size) { if ($size > Config::UPLOAD_MAX_SIZE_AUDIO) { throw new Exception(__('POST_ADD_ERROR_AUDIO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_AUDIO)))); } } if ($filepaths = File::upload('attachment_audio')) { foreach ($filepaths as $filepath) { $uploaded_files[] = $filepath; } foreach ($filepaths as $i => $filepath) { if (!preg_match('#\\.mp3$#', $filepath)) { throw new Exception(__('POST_ADD_ERROR_AUDIO_FORMAT')); } $name = isset($_FILES['attachment_audio']['name'][$i]) ? $_FILES['attachment_audio']['name'][$i] : ''; $attachments[] = array($filepath, $name); } } } // Files if (isset($_FILES['attachment_file']) && is_array($_FILES['attachment_file']['name'])) { foreach ($_FILES['attachment_file']['size'] as $size) { if ($size > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } } if ($filepaths = File::upload('attachment_file')) { foreach ($filepaths as $filepath) { $uploaded_files[] = $filepath; } foreach ($filepaths as $i => $filepath) { if (!preg_match('#\\.[a-z0-9]{2,4}$#i', $filepath)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } if (preg_match('#\\.(jpg|png|gif|mp3|flv)$#i', $filepath)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT2')); } $name = isset($_FILES['attachment_file']['name'][$i]) ? $_FILES['attachment_file']['name'][$i] : ''; $attachments[] = array($filepath, $name); } } } // Event if (isset($_POST['event_title']) && isset($_POST['event_start']) && isset($_POST['event_end'])) { // Title $event_title = trim($_POST['event_title']); if ($event_title == '') { throw new Exception(__('POST_ADD_ERROR_EVENT_NO_TITLE')); } // Dates if (!($event_start = strptime($_POST['event_start'], __('PUBLISH_EVENT_DATE_FORMAT')))) { throw new Exception(__('POST_ADD_ERROR_EVENT_DATE')); } if (!($event_end = strptime($_POST['event_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) { throw new Exception(__('POST_ADD_ERROR_EVENT_DATE')); } $event_start = mktime($event_start['tm_hour'], $event_start['tm_min'], 0, $event_start['tm_mon'] + 1, $event_start['tm_mday'], $event_start['tm_year'] + 1900); $event_end = mktime($event_end['tm_hour'], $event_end['tm_min'], 0, $event_end['tm_mon'] + 1, $event_end['tm_mday'], $event_end['tm_year'] + 1900); if ($event_start > $event_end) { throw new Exception(__('POST_ADD_ERROR_EVENT_DATE_ORDER')); } $event = array($event_title, $event_start, $event_end); } else { $event = null; } // Survey if (isset($_POST['survey_question']) && isset($_POST['survey_end']) && isset($_POST['survey_answer']) && is_array($_POST['survey_answer'])) { // Question $survey_question = trim($_POST['survey_question']); if ($survey_question == '') { throw new Exception(__('POST_ADD_ERROR_SURVEY_NO_QUESTION')); } // Date if (!($survey_end = strptime($_POST['survey_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) { throw new Exception(__('POST_ADD_ERROR_SURVEY_DATE')); } $survey_end = mktime($survey_end['tm_hour'], $survey_end['tm_min'], 0, $survey_end['tm_mon'] + 1, $survey_end['tm_mday'], $survey_end['tm_year'] + 1900); // Multiple answers $survey_multiple = isset($_POST['survey_multiple']); // Answers $survey_answers = array(); foreach ($_POST['survey_answer'] as $survey_answer) { $survey_answer = trim($survey_answer); if ($survey_answer != '') { $survey_answers[] = $survey_answer; } } if (count($survey_answers) < 2) { throw new Exception(__('POST_ADD_ERROR_SURVEY_ANSWERS')); } $survey = array($survey_question, $survey_end, $survey_multiple, $survey_answers); } else { $survey = null; } // Creation of the post $id = $this->model->addPost((int) User_Model::$auth_data['id'], $message, $category, $group, $official, $private); // Attach files foreach ($attachments as $attachment) { $this->model->attachFile($id, $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null); } // Event if (isset($event)) { $this->model->attachEvent($id, $event[0], $event[1], $event[2]); } // Survey if (isset($survey)) { $this->model->attachSurvey($id, $survey[0], $survey[1], $survey[2], $survey[3]); } $this->addJSCode(' parent.location = "' . Config::URL_ROOT . Routes::getPage('home') . '"; '); } catch (Exception $e) { // Delete all uploading files in tmp foreach ($uploaded_files as $uploaded_file) { File::delete($uploaded_file); } $this->addJSCode(' with(parent){ Post.errorForm(' . json_encode($e->getMessage()) . '); } '); } }
public function generateFFMPEG() { $ff = new ffmpeg_movie($this->path . $this->data['path'] . '/' . $this->data['name']); if (!$ff) { $this->unknown = true; return false; } $this->info = array('width' => $ff->getFrameWidth(), 'height' => $ff->getFrameHeight(), 'duration' => $ff->getDuration(), 'mime' => $this->mime, 'size' => filesize($this->path . $this->data['path'] . '/' . $this->data['name'])); if ($ff->getFrameCount() > 20) { $frame = $frame = $ff->getFrame(20); } else { $frame = $frame = $ff->getFrame($ff->getFrameCount() - 1); } $gd = $frame->toGDImage(); $this->generateGDimage($gd, 'video'); $this->updateDB(); }
<?php // Set our source file $srcFile = "/path/to/clock.avi"; $destFile = "/path/to/clock.flv"; $ffmpegPath = "/path/to/ffmpeg"; $flvtool2Path = "/path/to/flvtool2"; // Create our FFMPEG-PHP class $ffmpegObj = new ffmpeg_movie($srcFile); // Save our needed variables $srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth()); $srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight()); $srcFPS = $ffmpegObj->getFrameRate(); $srcAB = intval($ffmpegObj->getAudioBitRate() / 1000); $srcAR = $ffmpegObj->getAudioSampleRate(); // Call our convert using exec() exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile); // Make multiples function function makeMultipleTwo($value) { $sType = gettype($value / 2); if ($sType == "integer") { return $value; } else { return $value - 1; } } ?>
function captureVideoPosterImg($movie_file = '') { extension_loaded('ffmpeg'); $movie_file = 'http://upload.freelabel.net/server/php/files/JXL%20%23CrunkDUpTour%20Promo.mp4'; // Instantiates the class ffmpeg_movie so we can get the information you want the video $movie = new ffmpeg_movie($movie_file); // Get The duration of the video in seconds echo $Duration = round($movie->getDuration(), 0); // Get the number of frames of the video $TotalFrames = $movie->getFrameCount(); // Get the height in pixels Video $height = $movie->getFrameHeight(); // Get the width of the video in pixels $width = $movie->getFrameWidth(); //Receiving the frame from the video and saving // Need to create a GD image ffmpeg-php to work on it $image = imagecreatetruecolor($width, $height); // Create an instance of the frame with the class ffmpeg_frame $Frame = new ffmpeg_frame($image); // Choose the frame you want to save as jpeg $thumbnailOf = (int) round($movie->getFrameCount() / 2.5); // Receives the frame $frame = $movie->GetFrame($thumbnailOf); // Convert to a GD image $image = $frame->toGDImage(); // Save to disk. //echo $movie_file.'.jpg'; imagejpeg($image, $movie_file . '.jpg', 100); return $movie_file . '.jpg'; }