Ffmpeg-php converts video format to flv format implementation code

Source: Internet
Author: User

This article introduces a plug-in that uses ffmpeg-php to convert the video format to flv format, so that we can use this plug-in to convert the video format.

The following is a reference class for windows.

The Code is as follows: Copy code

Define ("ROOT_DIR", dirname (_ FILE __));
Class EcodeFlv {
Var $ fromFile; // uploaded file
Var $ toFilePath; // save the file path
Var $ toPicPath; // Save the image path
Var $ mpeg; // path of the ffmpeg program file
Var $ mencode; // the path of the mencode program file
Var $ convert tofile; // convert the file command
Var $ convert topic; // convert image command
Var $ toFileName; // converted file name
Var $ mpegComm; // The conversion command of ffmpeg.exe
Var $ mencodeComm; // mencode.exe command
Var $ mpegType;
Var $ mencodeType;
Var $ midi; // the path of mdi.exe
Var $ unzip MIDI; // mdi.exe command
// Initialization class
Function EcodeFlv ($ fromFile, $ toFilePath, $ toPicPath, $ mpeg, $ mencode, $ midi ){
$ This-> mpegComm = false;
$ This-> mencodeComm = false;
$ This-> fromFile = $ fromFile;
$ This-> toFilePath = $ toFilePath;
$ This-> toPicPath = ROOT_DIR. "/". $ toPicPath;
$ This-> mpeg = ROOT_DIR. $ mpeg;
$ This-> mencode = ROOT_DIR. $ mencode;
$ This-> midi = ROOT_DIR. $ midi;
$ This-> mpegType = array (
"Audio/x-mpeg" => ". mp3 ",
"Video/mpeg" => ". mpeg ",
"Video/3gpp" => ". 3gp ",
"Video/x-ms-asf" => ". asf ",
"Video/x-msvideo" => ". avi"
);
$ This-> mencodeType = array (
"Application/vnd. rn-realmedia" => ". rm ",
"Audio/x-pn-realaudio" => ". rmvb ",
"Audio/x-ms-wmv" => ". wmv ",
);
} // Check the file type

Function checkType (){
If (function_exists (mime_content_type )){
Return false;
} Else {
// $ ContentType = mime_content_type ($ this-> fromFile );
$ Exe = "D: serverphpextrasmagic ";
$ Handel = new finfo (FILEINFO_MIME, $ exe );
$ ContentType = $ handel-> file ($ this-> fromFile );
}
Foreach ($ this-> mpegType as $ index => $ key ){
If ($ contentType = $ index ){
$ Name = md5 (date ("Ymd"). tiime ());
$ This-> toFileName = $ name;
$ This-> $ mpegComm = true;
Return true;
}
}
Foreach ($ this-> mencodeType as $ index => $ key ){
If ($ contentType = $ index ){
$ Name = md5 (date ("Ymd"). time ());
$ This-> toFileName = $ name;
$ This-> mencodeComm = true;
Return true;
} Else {
Return false;
}
}
}

// Set the file, image size "> image size
Function setSize ($ flvSize, $ picSize ){
$ FlvWidth = $ flvSize [0];
$ FlvHeight = $ flvSize [1];
$ PicWidth = $ picSize [0];
$ PicHeight = $ picSize [1];
$ PicName = $ this-> toPicPath. $ this-> toFileName. ". jpg ";
$ FlvName = $ this-> toFilePath. $ this-> toFileName. ". flv ";
$ ToMdi = ROOT_DIR. "/". $ flvName;
$ Size = $ picWidth. "x". $ picHeight;
If ($ this-> mpegComm ){
$ This-> export tofile = "$ this-> mpeg-I $ this-> fromFile-y-AB 56-ar 22050-B 500-r 15-s $ flvWith * $ flvHeight $ flvName ";
}
Elseif ($ this-> mencodeComm ){
$ This-> export tofile = "$ this-> mencode $ this-> fromFile-vf scale = $ flvWidth: $ flvHeight-ffourcc FLV1-of lavf-ovc lavc-lavcopts vcodec = flv: vbitrate = 70: acodec = mp3: abitrate = 56: dia =-1-ofps 25-srate 22050-oac mp3lame-o $ flvName ";
}
$ This-> reply topic = "$ this-> mpeg-I $ toMdi-y-f image2-ss 8-t 0.003-s $ size $ picName ";
$ This-> midi = "$ this-> midi $ toMdi/k ";
Echo $ this-> reply topic;
}

// Start Conversion
Function toEcode (){
Set_time_limit (0 );
Exec ($ this-> export tofile, $ flvStatus)
Exec ($ this-> reply topic, $ picStatus );
Exec ($ this-> semi Midi, $ mStatus );
}

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.