Grab Image, Convert video to H264 single php

this is a updated code, provided by Steve, this single php file will grab image from input video and convert video to h264.

flv_convert_get_thumb('input.avi', 'output.jpg', 'output.ogm');
// code provided and updated by steve of phpsnaps ! thanks
// accepts:
// 1: the input video file
// 2: path to thumb jpg
// 3: path to transcoded mpeg?
function flv_convert_get_thumb($in, $out_thumb, $out_vid)
  // get thumbnail
  $cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 5 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$out_thumb;
  $res = shell_exec($cmd);
  // $res is the output of the command
  // transcode video
  $cmd = 'mencoder '.$in.' -o '.$out_vid.' -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=500:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame';
  $res = shell_exec($cmd);


Line, 3 is where you input your video, the output.jpg is the output mpeg also called jpg image format which will be be grabbed. the output.ogm is the actual encoded video. ogm is just a open source video container like avi mkv etc. you can change it to whatever suits your needs.

Line 12, deals with the image grabbing which uses ffmpeg, not much to be said here.

Line 16, deals with Mencoder this basically is the encoding engine, here you can change bit-rate, video width and height and aspect ratio. and volume control.

Dependency packages and operating systems

1. Ubuntu 8.10 Desktop or Server version
2. Lamp server - php5 CLI everything that includes inside Lamp server
3. FFmpeg
4. Mencoder

thanks it.


Add your comment