/**
  * 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);
 }
Beispiel #3
0
    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>';
}
/* FUNCTIONS */
Beispiel #4
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... */
    }
}
    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++;
}
echo '</div></body></html>';