大家好,我有一个像youtube这样的视频托管网站,我允许上传几乎所有类型的视频,但我想将所有上传的视频转换为mp4格式
我可以做到这一点,我的代码在下面
require 'vendor/autoload.php';
$getEXT_check=substr(@$_FILES['profileimage99']['name'],-3);
if($getEXT_check !='mp4' || $getEXT_check !='MP4'){
exec('ffmpeg -i '.$uploadfile.' -f mp4 -s 896x504 '.$new_flv.''); }
//execute ffmpeg and create thumb
exec('ffmpeg -i '.$uploadfile.' -ss 00:00:28.435 -vframes 1 '.$new_image_path);
$theduration=exec('ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 '.$uploadfile.' 2>&1');
$theduration_val=round($theduration/60, 2);
这段代码将非mp4视频转换为mp4,并获得缩略图和正确的持续时间,但问题是,如果我上传大约100mbs的flv或mkv格式,这个过程需要非常长的时间,比如超过2-3小时。
如果你需要看完整的代码,请给我一些更好的建议
完整代码:
<?php
@session_start();
include "conn.php";
include "date.php";
$sid = $_SESSION['id'];
$ipIP=$_SERVER['REMOTE_ADDR'];
$uploaddir = "members/$sid/video/";
//Check the file is of correct format.
function checkfile($input){
$ext = array('mpg', 'wma', 'mov', 'flv', 'mp4', 'avi', 'qt', 'wmv', 'rm', 'mkv', 'MP4','3gp');
$extfile = substr($input['name'],-4);
$extfile = explode('.',$extfile);
$good = array();
@$extfile = $extfile[1];
if(in_array($extfile, $ext)){
$good['safe'] = true;
$good['ext'] = $extfile;
}else{
$good['safe'] = false;
}
return $good;
}
if($_FILES["profileimage99"]["size"] ==''){
echo 'No file added';die;
}
// if the form was submitted process request if there is a file for uploading
if(@$_FILES["profileimage99"]["size"] < 102400000000){
//$live_dir is for videos after converted to mp4
$live_dir = "mem/$sid/video/";
//$live_img is for the first frame thumbs.
$live_img = "mem/$sid/img/";
$seed = rand(11111111111193,9999999999999929) * rand(3,9);
$getEXT=substr(@$_FILES['profileimage99']['name'],-5);
$upload = $seed.$getEXT;
$uploadfile = $uploaddir .$upload;
$safe_file = checkfile(@$_FILES['profileimage99']);
if($safe_file['safe'] == 1){
if (move_uploaded_file(@$_FILES['profileimage99']['tmp_name'], $uploadfile)) {
$base = basename($uploadfile, $safe_file['ext']);
$new_file = $base.'mp4';
$new_image = $base.'jpg';
$new_image_path = $live_img.$new_image;
$new_flv = $live_dir.$new_file;
require 'vendor/autoload.php';
$getEXT_check=substr(@$_FILES['profileimage99']['name'],-3);
if($getEXT_check !='mp4' || $getEXT_check !='MP4'){
exec('ffmpeg -i '.$uploadfile.' -f mp4 -s 896x504 '.$new_flv.''); }
//execute ffmpeg and create thumb
exec('ffmpeg -i '.$uploadfile.' -ss 00:00:28.435 -vframes 1 '.$new_image_path);
$theduration=exec('ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 '.$uploadfile.' 2>&1');
$theduration_val=round($theduration/60, 2);
//create query to store video
if(isset($_POST['title'])){$titlename=$_POST['title'];}else{$titlename='';}
if(isset($_POST['desc'])){$desc=$_POST['desc'];}else{$desc='';}
if(isset($_POST['catag'])){$catag=$_POST['catag'];}else{$catag='';}
if(isset($_POST['channel'])){$channel=$_POST['channel'];}else{$channel='';}
$dbentry_o=mysqli_query($conn,"insert into vids (uid,chid,ctid,vname,vdisc,duration,time,ip,src,thumb) values ('$sid','$channel','$catag','$titlename','$desc','$theduration_val','$date','$ipIP','$new_file','$new_image')");
echo "<img src='mem/$sid/img/$new_image' class='The_Append_L_snap'/>";die;
} else {
echo "Possible file upload attack!\n";
print_r($_FILES);
}
}else{
echo 'Invalid File Type Please Try Again. You file must be of type
.mpg, .wma, .mov, .flv, .mp4, .avi, .qt, .wmv, .rm'.$_FILES['profileimage99']['name'];
}
}else{
echo 'Please choose a video';die;
}
?>
问题:上面的FFmpeg调用需要花费太多时间才能将视频转换为MP4。
注意:
在未来我将有一个质量选择器在我的video.js
播放器。
从这篇文章
The general guideline is to use the slowest preset that you have patience for. Current presets in descending order of speed are: ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. The default preset is medium. Ignore placebo as it is not useful (see FAQ). You can see a list of current presets with -preset help (see example below), and what settings they apply with x264 --fullhelp.
您可以使用-预设超快速
,但要注意质量
附加链接
https://superuser.com/questions/490683/cheat-sheets-and-presets-settings-that-actually-work-with-ffmpeg-1-0
https://askubuntu.com/questions/352920/fastest-way-to-convert-videos-batch-or-single
下载示例链接:
ffmpeg 是 *nix 系统下最流行的音视频处理库,功能强大,并且提供了丰富的终端命令,实是日常视频处理的一大利器! 实例 flac 格式转 mp3 音频格式转换非常简单:ffmpeg -i input.flac -acodec libmp3lame output.mp3。 ffmpeg 将会使用 libmp3lame 解码器将 input.flac 文件转换为 mp3 格式的 output.
我在另一个论坛上问过这个问题,但从来没有运气。我在网上找到了下面的命令,它应该使用FFMPEG从图像创建一个视频(每个持续时间为5秒)。 FFMPEG-F image2-r 1/5-i img%03d.png-vcodec libx264 out.mp4 编辑:添加命令行输出
问题内容: 这个问题 不是 关于将long正确地强制转换为int,而是当我们将其错误地强制转换为int时会发生什么。 因此,请考虑以下代码- 这给出了输出- 现在假设我进行以下更改- 然后我得到输出- 问题是, 如何 将long的值转换为int? 问题答案: 的低32位被取出并放入。 不过,这是数学运算: 将负值视为该值的正值。因此被视为2 ^ 64-1。(这是 无符号的 64位值,这是该值实际以
我正在尝试将excel文件转换为XSSFWorkbook,我有大约7000行和大约145列。将excel文件转换为第2行的XSSFWorkbook大约需要15分钟,代码如下:- 我不想向XFFSWorkbook添加7000行,只想在第2行转换时向XFFSWorkbook添加30行? 如果没有,如何减少将excel转换为XSSFWorkbook所需的时间?
它是一个后端API(由RubyonRails开发),iphone和android手机使用它上传视频。API正在将上传的视频转换为MP4格式。我在后端使用曲别针ffmpeg gem进行视频转换。以下是我使用的: 我面临的问题有: 当用户从Android手机上传视频时,它在Android手机上运行良好,但在iPhone上无法播放。当用户从iPhone上传视频时,会发生另一件奇怪的事情,视频上传后,它会