Home Backend Development PHP Tutorial ffmpeg-php converts video format to flv format implementation code_PHP tutorial

ffmpeg-php converts video format to flv format implementation code_PHP tutorial

Jul 20, 2016 am 11:10 AM
flv code use accomplish Will plug-in article Format video

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

The following is a reference class, the platform uses windows.

The code is as follows
 代码如下 复制代码

define("ROOT_DIR",dirname(__FILE__));
class EcodeFlv {
var $fromFile;   //上传来的文件
var $toFilePath;  //保存文件路径
var $toPicPath;  //保存图片路径
var $mpeg; //ffmpeg程序文件的路径
var $mencode; //mencode程序文件的路径
var $cmdToFile; //转换文件命令
var $cmdToPic;  //转换图片命令
var $toFileName; //转换后的文件名
var $mpegComm; //ffmpeg.exe的转换命令
var $mencodeComm; //mencode.exe的命令
var $mpegType;
var $mencodeType;
var $midi; //mdi.exe的路径
var $cmdMidi; //mdi.exe的命令
//初始化类
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",
);
} //检查文件类型

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

//设置文件,图片大小">图片大小
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 $flvName";
}
elseif($this->mencodeComm){
$this->cmdToFile = "$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->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;
}

//开始转换
function toEcode() {
set_time_limit(0);
exec($this->cmdToFile,$flvStatus)
exec($this->cmdToPic,$picStatus);
exec($this->cmdMidi,$mStatus);
}

}

Copy code
define("ROOT_DIR",dirname(__FILE__));
class EcodeFlv {
var $fromFile; //Uploaded file
var $toFilePath; // Save file path
var $toPicPath; //Save picture path
var $mpeg; //Path of ffmpeg program file
var $mencode; //Path of mencode program file
var $cmdToFile; //Convert file command
var $cmdToPic; //Convert picture command
var $toFileName; //Converted file name
var $mpegComm; //ffmpeg.exe Conversion command
var $mencodeComm; //command of mencode.exe
var $mpegType;
var $mencodeType;
var $midi; //path to mdi.exevar $cmdMidi; //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 file typefunction 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 file, picture size">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 $flvName";
}
elseif ($this->mencodeComm){
$this->cmdToFile = "$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- >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);
}}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444712.htmlTechArticleThis article introduces a plug-in that uses ffmpeg-php to convert video formats to flv format, so that we can convert videos in many formats You can use this plug-in to achieve format conversion. The following is a reference...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is it infringing to post other people's videos on Douyin? How does it edit videos without infringement? Is it infringing to post other people's videos on Douyin? How does it edit videos without infringement? Mar 21, 2024 pm 05:57 PM

With the rise of short video platforms, Douyin has become an indispensable part of everyone's daily life. On TikTok, we can see interesting videos from all over the world. Some people like to post other people’s videos, which raises a question: Is Douyin infringing upon posting other people’s videos? This article will discuss this issue and tell you how to edit videos without infringement and how to avoid infringement issues. 1. Is it infringing upon Douyin’s posting of other people’s videos? According to the provisions of my country's Copyright Law, unauthorized use of the copyright owner's works without the permission of the copyright owner is an infringement. Therefore, posting other people’s videos on Douyin without the permission of the original author or copyright owner is an infringement. 2. How to edit a video without infringement? 1. Use of public domain or licensed content: Public

How to make money from posting videos on Douyin? How can a newbie make money on Douyin? How to make money from posting videos on Douyin? How can a newbie make money on Douyin? Mar 21, 2024 pm 08:17 PM

Douyin, the national short video platform, not only allows us to enjoy a variety of interesting and novel short videos in our free time, but also gives us a stage to show ourselves and realize our values. So, how to make money by posting videos on Douyin? This article will answer this question in detail and help you make more money on TikTok. 1. How to make money from posting videos on Douyin? After posting a video and gaining a certain amount of views on Douyin, you will have the opportunity to participate in the advertising sharing plan. This income method is one of the most familiar to Douyin users and is also the main source of income for many creators. Douyin decides whether to provide advertising sharing opportunities based on various factors such as account weight, video content, and audience feedback. The TikTok platform allows viewers to support their favorite creators by sending gifts,

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

How to post videos on Weibo without compressing the image quality_How to post videos on Weibo without compressing the image quality How to post videos on Weibo without compressing the image quality_How to post videos on Weibo without compressing the image quality Mar 30, 2024 pm 12:26 PM

1. First open Weibo on your mobile phone and click [Me] in the lower right corner (as shown in the picture). 2. Then click [Gear] in the upper right corner to open settings (as shown in the picture). 3. Then find and open [General Settings] (as shown in the picture). 4. Then enter the [Video Follow] option (as shown in the picture). 5. Then open the [Video Upload Resolution] setting (as shown in the picture). 6. Finally, select [Original Image Quality] to avoid compression (as shown in the picture).

How to publish Xiaohongshu video works? What should I pay attention to when posting videos? How to publish Xiaohongshu video works? What should I pay attention to when posting videos? Mar 23, 2024 pm 08:50 PM

With the rise of short video platforms, Xiaohongshu has become a platform for many people to share their lives, express themselves, and gain traffic. On this platform, publishing video works is a very popular way of interaction. So, how to publish Xiaohongshu video works? 1. How to publish Xiaohongshu video works? First, make sure you have a video content ready to share. You can use your mobile phone or other camera equipment to shoot, but you need to pay attention to the image quality and sound clarity. 2. Edit the video: In order to make the work more attractive, you can edit the video. You can use professional video editing software, such as Douyin, Kuaishou, etc., to add filters, music, subtitles and other elements. 3. Choose a cover: The cover is the key to attracting users to click. Choose a clear and interesting picture as the cover to attract users to click on it.

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Douyin 15 seconds is too short and I want to extend it. How can I extend it? How to make a video longer than 15 seconds? Douyin 15 seconds is too short and I want to extend it. How can I extend it? How to make a video longer than 15 seconds? Mar 22, 2024 pm 08:11 PM

With the popularity of Douyin, more and more people like to share their lives, talents and creativity on this platform. Douyin's 15-second limit makes many users feel that it is not enjoyable enough and hope to extend the video duration. So, how can you extend the video duration on Douyin? 1. Douyin 15 seconds is too short and I want to extend it. How can I extend it? 1. The most convenient way to shoot multiple videos and splice them is to record multiple 15-second videos, and then use the editing function of Douyin to combine them. When recording, make sure to leave some blank space at the beginning and end of each video for later splicing. The length of the spliced ​​video can be several minutes, but this may cause the video screen to switch too frequently, affecting the viewing experience. 2. Use Douyin special effects and stickers Douyin provides a series of special effects

How to check the release time of Xiaohongshu videos? How to remove the watermark and save its videos? How to check the release time of Xiaohongshu videos? How to remove the watermark and save its videos? Mar 22, 2024 pm 02:58 PM

With the rise of short video platforms, Xiaohongshu has become an important way for many people to share their lives and get inspiration. Many users may encounter a problem when watching Xiaohongshu videos: How to check the release time of the video? This article will discuss "How to check the release time of Xiaohongshu videos" and share how to remove watermarks and save Xiaohongshu videos. 1. How to check the release time of Xiaohongshu videos? In the Xiaohongshu APP, when you open a video, a timestamp will be displayed at the bottom of the screen to show the release date and time of the video. Just swipe down or scroll to the bottom of the video to easily see when it was posted. In Xiaohongshu, if you remember the video publisher or content, you can use the search bar to enter the user's nickname or video keywords, and then click search. Search

See all articles