Use php to convert videos of any format into flv code _ PHP Tutorial

Source: Internet
Author: User
Convert any video format into flv code using php. Copy the code as follows :? Define (ROOT_DIR, dirname (_ FILE _); classEcodeFlv {var $ fromFile; uploaded FILE var $ toFilePath; save FILE path var $ toPicPath; save The code is as follows:


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.exe file
Var $ mencode; // The path of the mencode.exe 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: \ server \ php \ extras \ magic ";
$ 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 and 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 );
}

}
?>

The http://www.bkjia.com/PHPjc/320525.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320525.htmlTechArticle code is as follows :? Define ("ROOT_DIR", dirname (_ FILE _); class EcodeFlv {var $ fromFile; // uploaded FILE var $ toFilePath; // Save the file path var $ toPicPath; // save...

Related Article

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.