我们的代码如下。将上传的.mov
转换为.mp4
时,转化次数将停止在98%。
几乎所有其他首选格式都可以完美编码。任何人都知道我们哪里出错了?我们现在正在努力解决这个问题,所以我们想问专家,提前感谢您的帮助。
<?php
$Path = dirname(__FILE__) . "/";
$url = "http://" . $_SERVER['SERVER_NAME'] . str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])) . "/";
session_start();
include_once 'inc/config.inc.php';
include_once 'common.php';
include_once 'inc/ffmpegprogressbar.class.php';
ob_flush();
?>
<html>
<head>
<title>Converting..........</title>
<style type="text/css">
#mainDiv{
margin:auto 0;
text-align: center;
}
#progressbar_pbText{
display: block; margin-top: -22px;
}
#fileInformation{
color: red; padding: 16px;
}
</style>
<?php
// Specifie Inputfile for FFMPEG
$count = count($_SESSION['Files']);
// $file = array_pop($_SESSION['Files']);
$FileInstance = array_pop($_SESSION['Files']);
//$FileInstance = $_SESSION['Files'][0];
$file = $FileInstance['FileName'];
$passNeeded = $FileInstance['PassNeeded'];
$fmt = $FileInstance['fmt'];
$FFMPEGInput = $Path . 'data/' . $_SESSION['OldSession'] . "/" . $file;
$timeUnique = time();
//echo "Start:Session holds: ".$_SESSION["cstatus"].", cstatus var = $cstatus";
/* if ($FileInstance['PassNeeded'] == 5) {
$FFMPEGParams = "-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 1920x1080";
} else if ($FileInstance['PassNeeded'] == 4) {
$FFMPEGParams ="-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 1280x720";
} else if ($FileInstance['PassNeeded'] == 3) {
$FFMPEGParams = "-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 854x480";
} else if ($FileInstance['PassNeeded'] == 2) {
$FFMPEGParams = "-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 640x360";
}
*/
if($fmt=="flv"){
if ($FileInstance['PassNeeded'] == 5) {
$FFMPEGParams = "-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 1920x1080";
} else if ($FileInstance['PassNeeded'] == 4) {
$FFMPEGParams ="-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 1280x720";
} else if ($FileInstance['PassNeeded'] == 3) {
$FFMPEGParams = "-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 854x480";
} else if ($FileInstance['PassNeeded'] == 2) {
$FFMPEGParams = "-r 1000 -ar 11025 -ab 32 -f $fmt -sameq -g 15 -s 640x360";
}
}elseif($fmt=="mp4"){
$FFMPEGParams = " -pix_fmt yuv420p -s 640x360";
}elseif($fmt=="ogv"){
$FFMPEGParams = " -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 125k -s 640x360";
}elseif($fmt=="webm"){
$FFMPEGParams = " -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 125k -s 640x360";
//}elseif($fmt!==""){
//-i %1 -s qvga -acodec libfaac -ar 22050 -ab 128k -vcodec libx264 -threads 0 -f ipod %2
//-vcodec mpeg4 -acodec aac output.mp4
//$FFMPEGParams = "-r 20 -ar 44100 -ab 196 -f $fmt -s 480x351";
}
if ($FileInstance['PassNeeded'] > 2) {
$FileInstance['PassNeeded'] = $FileInstance['PassNeeded'] - 1;
array_unshift($_SESSION['Files'], $FileInstance);
}
$flv_rpath = 'data/' . $_SESSION['OldSession'] . "/" . $file. $timeUnique . ".".$fmt;
$FFMPEGOutput = $FFMPEGInput . $timeUnique . ".$fmt";
$_SESSION['ConvertedFiles'][$file][] = array('Pass' => $passNeeded, 'OutFile' => $file . $timeUnique . ".$fmt","fmt"=>$fmt);
if (!$_GET["pkey"]) {
$pkey = rand();
} elseif (file_exists('log/' . $_GET["pkey"] . '.ffmpeg')) {
$pkey = $_GET["pkey"];
} else {
$pkey = rand();
}
// initializing and create ProgressBar
flush();
$FFMPEGProgressBar = &new FFMPEGProgressBar();
flush();
// Show Progressbar
if ($count > 0) {
if ($FileInstance['PassNeeded'] < 3) {
define('FFMPEG_LIBRARY', '/usr/local/bin/ffmpeg ');
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
if (!extension_loaded($extension)) {
dl($extension_soname) or die("Can't load extension $extension_fullname\n");
}
exec(FFMPEG_LIBRARY . " -y -i '" . $FFMPEGInput . "' -vframes 1 -ss 00:00:03 -an -vcodec png -f rawvideo -s 160x90 '$FFMPEGInput.png'");
}
$FFMPEGProgressBar->Show($pkey, $count, $url, $passNeeded, $file, $timeUnique,$fmt);
if (!$_GET["pkey"] || !file_exists('log/' . $_GET["pkey"] . '.ffmpeg')) {
flush();
$FFMPEGProgressBar = &new FFMPEGProgressBar();
flush();
@$FFMPEGProgressBar->execFFMPEG($FFMPEGInput, $FFMPEGOutput, $FFMPEGParams, $pkey);
flush();
$_SESSION['new_space']["video"] = 'data/' . $_SESSION['OldSession'] . "/" . $file;
$_SESSION['new_space']["{$FileInstance['name']}"] = $flv_rpath;
$_SESSION['new_space']["session"] = $_SESSION['OldSession'];
}
//echo "End:Session holds: ".$_SESSION["cstatus"].", cstatus var = $cstatus";
} else {
// header("Location: $url" . "index.php" );
echo "<script type=\"text/javascript\">window.location.href='" . $url . "';</script><error>No Input</error>";
}
// ShowProgressbar
?>