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("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>'; } /* FUNCTIONS */ function print_class_methods($class)
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++; } echo '</div></body></html>'; if (php_sapi_name() == 'cli') {