Use PHP to convert any format video to FLV code _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
Define ("Root_dir", DirName (__file__));
Class Ecodeflv {
var $fromFile; The papers that came on
var $toFilePath; Save File path
var $toPicPath; Save Picture Path
var $mpeg; Path to the Ffmpeg.exe file
var $mencode; Path to the Mencode.exe file
var $cmdToFile; Convert File command
var $cmdToPic; Convert Picture command
var $toFileName; The converted file name
var $mpegComm; Conversion commands for Ffmpeg.exe
var $mencodeComm; Mencode.exe's command.
var $mpegType;
var $mencodeType;
var $midi; Path of the Mdi.exe
var $cmdMidi; Mdi.exe's command.
Initialize 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 file types

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;
}
}
}

Settings file, picture 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->cmdtofile= "$this->mpeg-i $this->fromfile-y-ab 56-ar 22050-b 500-r 15-s $flvWith * $flvHeight $flvNam E ";
}
ElseIf ($this->mencodecomm) {
$this->cmdtofile = "$this->mencode $this->fromfile-vf scale= $flvWidth: $flvHeight-ffourcc flv1-of lavf-ovc LA Vc-lavcopts vcodec=flv:vbitrate=70:acodec=mp3:abitrate=56:dia=-1-ofps 25-srate 22050-OAC mp3lame-o $flvName ";
}
$this->cmdtopic = "$this->mpeg-i $toMdi-y-F image2-ss 8-t 0.003-s $size $picName";
$this->cmdmidi = "$this->midi $toMdi/k";
Echo $this->cmdtopic;
}

Start conversion
function Toecode () {
Set_time_limit (0);
EXEC ($this->cmdtofile, $flvStatus)
EXEC ($this->cmdtopic, $picStatus);
EXEC ($this->cmdmidi, $mStatus);
}

}
?>

http://www.bkjia.com/PHPjc/320525.html www.bkjia.com true http://www.bkjia.com/PHPjc/320525.html techarticle Copy the code as follows: Define ("Root_dir", DirName (__file__)), class ecodeflv {var $fromFile;//file var $toFilePath;//Save 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.