/**
  * 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);
 }
示例#2
0
echo "--------------------\n\n";
foreach ($movies as $movie) {
    $mov = new ffmpeg_movie($movie);
    printf("file name = %s\n", $mov->getFileName());
    printf("duration = %s seconds\n", $mov->getDuration());
    printf("frame count = %s\n", $mov->getFrameCount());
    printf("frame rate = %0.3f fps\n", $mov->getFrameRate());
    printf("comment = %s\n", $mov->getComment());
    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');
示例#3
0
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... */
    }
}
 echo '<table width="90%" class="hor-minimalist-a">';
 printf('<caption>Processing Test File: %s...</caption>', basename($mov->getFilename()));
 printf('<thead><tr><th width="150">Method</th><th>Result<br/></th></tr></thead>', $mov->getFileName());
 printf("<tr><td>file name:</td><td>%s<br/></td></tr>", $mov->getFileName());
 printf("<tr><td>duration</td><td>%s seconds<br/></td></tr>", $mov->getDuration());
 printf("<tr><td>frame count</td><td>%s<br/></td></tr>", $mov->getFrameCount());
 printf("<tr><td>frame rate</td><td>%0.3f fps<br/></td></tr>", $mov->getFrameRate());
 printf("<tr><td>comment</td><td>%s<br/></td></tr>", $mov->getComment());
 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());