имам инсталиран wordpress+contus-hd-flv-player+video-flv-converter локално. как да вградя този скрипт
<?php
convertToFlv( "some-video-input.avi", "output.jpg" );
function convertToFlv( $input, $output ) {
echo "Converting $input to $output<br />";
$command = "ffmpeg -v 0 -y -i 3.mp4 -vframes 1 -ss 5 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 3.jpg ";
echo "$command<br />";
shell_exec( $command );
echo "Converted<br />";
}
?> или този
<?php
// where ffmpeg is located
$ffmpeg = 'C:\xampp\htdocs\ffmpeg\bin\ffmpeg';
// the input video file
$video = 'C:\xampp\htdocs\video/7.MP4';
// where you'll save the image
$image = 'C:\xampp\htdocs/image/7.jpg';
// default time to get the image
$second = 1;
// get the duration and a random place within that
$cmd = "$ffmpeg -i $video 2>&1";
if (preg_match('/Duration: ((\d+)\d+)\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
// get the screenshot
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:10 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";
$return = `$cmd`;
echo 'done!';
//display the thumbnail.
echo '';
?>
така че да взаимодейства с
upload.php
<?php
session_start();
session_regenerate_id();
// look up for the path
require_once( dirname(__FILE__) . '/hdflv-config.php');
// get the path url from querystring
function get_out_now() { exit; }
add_action('shutdown', 'get_out_now', -1);
$file_name = '';
$error = "";
$errorcode = 12;
$errormsg[0] = "<b>Upload Success:</b> File Uploaded Successfully";
$errormsg[1] = "<b>Upload Cancelled:</b> Cancelled by user";
$errormsg[2] = "<b>Upload Failed:</b> Invalid File type specified";
$errormsg[3] = "<b>Upload Failed:</b> Your File Exceeds Server Limit size";
$errormsg[4] = "<b>Upload Failed:</b> Unknown Error Occured";
$errormsg[5] = "<b>Upload Failed:</b> The uploaded file exceeds the upload_max_filesize directive in php.ini";
$errormsg[6] = "<b>Upload Failed:</b> The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
$errormsg[7] = "<b>Upload Failed:</b> The uploaded file was only partially uploaded";
$errormsg[8] = "<b>Upload Failed:</b> No file was uploaded";
$errormsg[9] = "<b>Upload Failed:</b> Missing a temporary folder";
$errormsg[10] = "<b>Upload Failed:</b> Failed to write file to disk";
$errormsg[11] = "<b>Upload Failed:</b> File upload stopped by extension";
$errormsg[12] = "<b>Upload Failed:</b> Unknown upload error.";
$errormsg[13] = "<b>Upload Failed:</b> Please check post_max_size in php.ini settings";
if (isset($_GET['error'])) {
$error = $_GET['error'];
}
if (isset($_GET['processing'])) {
$pro = $_GET['processing'];
}
if (isset($_POST['mode']))
{
$exttype = $_POST['mode'];
if ($exttype == 'video')
$allowedExtensions = array("flv", "FLV", "mp4", "MP4" , "m4v", "M4V", "M4A", "m4a", "MOV", "mov", "mp4v", "Mp4v", "F4V", "f4v");
else
$allowedExtensions = array("jpg", "JPG", "png", "PNG");
}
//check if upload cancelled
if (!iserror()) {
//check if stopped by post_max_size
if (($pro == 1) && (empty($_FILES['myfile']))) {
$errorcode = 13;
}
else {
$file = $_FILES['myfile'];
if (no_file_upload_error($file)) {
if (isAllowedExtension($file)) {
//check file size
if (!filesizeexceeds($file)) {
doupload($file);
}
}
}
}
}
function iserror() {
global $error;
global $errorcode;
if ($error == "cancel") {
$errorcode = 1;
return true;
}
else {
return false;
}
}
function no_file_upload_error($file) {
global $errorcode;
$error_code = $file['error'];
// echo '<script language="javascript" type="text/javascript">
// window.top.window.updateQueue(';
// echo $errorcode;
// echo ',"';
// echo $errormsg[$errorcode];
// echo '","';
// echo $error_code;
// echo '");</script>';
// exit();
switch ($error_code) {
case 1:
$errorcode = 5;
return false;
case 2:
$errorcode = 6;
return false;
case 3:
$errorcode = 7;
return false;
case 4:
$errorcode = 8;
return false;
case 6:
$errorcode = 9;
return false;
case 7:
$errorcode = 10;
return false;
case 8:
$errorcode = 11;
return false;
case 0:
return true;
default:
$errorcode = 12;
return false;
}
}
function isAllowedExtension($file) {
global $allowedExtensions;
global $errorcode;
$filename = $file['name'];
$output = in_array(end(explode(".", $filename)), $allowedExtensions);
if (!$output) {
$errorcode = 2;
return false;
}
else {
return true;
}
}
function filesizeexceeds($file) {
$POST_MAX_SIZE = ini_get('post_max_size');
$filesize = $file['size'];
$mul = substr($POST_MAX_SIZE, -1);
$mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
return true;
$errorcode = 3;
}
else {
return false;
}
}
function doupload($file) {
global $options1;
global $wptfile_abspath1;
$options1 = get_option('HDFLVSettings');
global $uploadpath;
global $file;
global $errorcode;
global $file_name;
global $wpdb;
if ($options1[0][27]['v'] == 0 ) {
$dir = ABSPATH.trim( $options1[0][28]['v'] ).'/';
$url = trailingslashit( get_option('siteurl') ).trim( $options1[0][28]['v']).'/';
// Make sure we have an uploads dir
if ( ! wp_mkdir_p( $dir ) ) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?','hdflv'), $dir);
$uploads['error'] = $message;
return $uploads;
}
$uploads = array('path' => $dir, 'url' => $url, 'error' => false);
$uploadpath =$uploads['path'];
}
else
{
$wp_upload = wp_upload_dir();
$uploadpath = $wp_upload['path'].'/';
}
$filesave= "select MAX(vid) from ".$wpdb->prefix."hdflv";
$fsquery = mysql_query( $filesave);
$row = mysql_fetch_array($fsquery , MYSQL_NUM);
$destination_path = $uploadpath;
$row1 = $row[0]+1;
$file_name = $row1."_".$_FILES['myfile']['name'];
$target_path = $destination_path ."". $file_name;
if(@move_uploaded_file($file['tmp_name'], $target_path))
{
$errorcode = 0;
}
else
{
$errorcode = 4;
}
sleep(1);
}
//echo $errormsg[$errorcode];
?>
<script language="javascript" type="text/javascript">
window.top.window.updateQueue(<?php echo $errorcode;
?>,"<?php echo $errormsg[$errorcode]; ?>","<?php echo $file_name; ?>");
</script>
Благодаря предварително.
<?php
convertToFlv( "some-video-input.avi", "output.jpg" );
function convertToFlv( $input, $output ) {
echo "Converting $input to $output<br />";
$command = "ffmpeg -v 0 -y -i 3.mp4 -vframes 1 -ss 5 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 3.jpg ";
echo "$command<br />";
shell_exec( $command );
echo "Converted<br />";
}
?> или този
<?php
// where ffmpeg is located
$ffmpeg = 'C:\xampp\htdocs\ffmpeg\bin\ffmpeg';
// the input video file
$video = 'C:\xampp\htdocs\video/7.MP4';
// where you'll save the image
$image = 'C:\xampp\htdocs/image/7.jpg';
// default time to get the image
$second = 1;
// get the duration and a random place within that
$cmd = "$ffmpeg -i $video 2>&1";
if (preg_match('/Duration: ((\d+)\d+)\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
// get the screenshot
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:10 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";
$return = `$cmd`;
echo 'done!';
//display the thumbnail.
echo '';
?>
така че да взаимодейства с
upload.php
<?php
session_start();
session_regenerate_id();
// look up for the path
require_once( dirname(__FILE__) . '/hdflv-config.php');
// get the path url from querystring
function get_out_now() { exit; }
add_action('shutdown', 'get_out_now', -1);
$file_name = '';
$error = "";
$errorcode = 12;
$errormsg[0] = "<b>Upload Success:</b> File Uploaded Successfully";
$errormsg[1] = "<b>Upload Cancelled:</b> Cancelled by user";
$errormsg[2] = "<b>Upload Failed:</b> Invalid File type specified";
$errormsg[3] = "<b>Upload Failed:</b> Your File Exceeds Server Limit size";
$errormsg[4] = "<b>Upload Failed:</b> Unknown Error Occured";
$errormsg[5] = "<b>Upload Failed:</b> The uploaded file exceeds the upload_max_filesize directive in php.ini";
$errormsg[6] = "<b>Upload Failed:</b> The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
$errormsg[7] = "<b>Upload Failed:</b> The uploaded file was only partially uploaded";
$errormsg[8] = "<b>Upload Failed:</b> No file was uploaded";
$errormsg[9] = "<b>Upload Failed:</b> Missing a temporary folder";
$errormsg[10] = "<b>Upload Failed:</b> Failed to write file to disk";
$errormsg[11] = "<b>Upload Failed:</b> File upload stopped by extension";
$errormsg[12] = "<b>Upload Failed:</b> Unknown upload error.";
$errormsg[13] = "<b>Upload Failed:</b> Please check post_max_size in php.ini settings";
if (isset($_GET['error'])) {
$error = $_GET['error'];
}
if (isset($_GET['processing'])) {
$pro = $_GET['processing'];
}
if (isset($_POST['mode']))
{
$exttype = $_POST['mode'];
if ($exttype == 'video')
$allowedExtensions = array("flv", "FLV", "mp4", "MP4" , "m4v", "M4V", "M4A", "m4a", "MOV", "mov", "mp4v", "Mp4v", "F4V", "f4v");
else
$allowedExtensions = array("jpg", "JPG", "png", "PNG");
}
//check if upload cancelled
if (!iserror()) {
//check if stopped by post_max_size
if (($pro == 1) && (empty($_FILES['myfile']))) {
$errorcode = 13;
}
else {
$file = $_FILES['myfile'];
if (no_file_upload_error($file)) {
if (isAllowedExtension($file)) {
//check file size
if (!filesizeexceeds($file)) {
doupload($file);
}
}
}
}
}
function iserror() {
global $error;
global $errorcode;
if ($error == "cancel") {
$errorcode = 1;
return true;
}
else {
return false;
}
}
function no_file_upload_error($file) {
global $errorcode;
$error_code = $file['error'];
// echo '<script language="javascript" type="text/javascript">
// window.top.window.updateQueue(';
// echo $errorcode;
// echo ',"';
// echo $errormsg[$errorcode];
// echo '","';
// echo $error_code;
// echo '");</script>';
// exit();
switch ($error_code) {
case 1:
$errorcode = 5;
return false;
case 2:
$errorcode = 6;
return false;
case 3:
$errorcode = 7;
return false;
case 4:
$errorcode = 8;
return false;
case 6:
$errorcode = 9;
return false;
case 7:
$errorcode = 10;
return false;
case 8:
$errorcode = 11;
return false;
case 0:
return true;
default:
$errorcode = 12;
return false;
}
}
function isAllowedExtension($file) {
global $allowedExtensions;
global $errorcode;
$filename = $file['name'];
$output = in_array(end(explode(".", $filename)), $allowedExtensions);
if (!$output) {
$errorcode = 2;
return false;
}
else {
return true;
}
}
function filesizeexceeds($file) {
$POST_MAX_SIZE = ini_get('post_max_size');
$filesize = $file['size'];
$mul = substr($POST_MAX_SIZE, -1);
$mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
return true;
$errorcode = 3;
}
else {
return false;
}
}
function doupload($file) {
global $options1;
global $wptfile_abspath1;
$options1 = get_option('HDFLVSettings');
global $uploadpath;
global $file;
global $errorcode;
global $file_name;
global $wpdb;
if ($options1[0][27]['v'] == 0 ) {
$dir = ABSPATH.trim( $options1[0][28]['v'] ).'/';
$url = trailingslashit( get_option('siteurl') ).trim( $options1[0][28]['v']).'/';
// Make sure we have an uploads dir
if ( ! wp_mkdir_p( $dir ) ) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?','hdflv'), $dir);
$uploads['error'] = $message;
return $uploads;
}
$uploads = array('path' => $dir, 'url' => $url, 'error' => false);
$uploadpath =$uploads['path'];
}
else
{
$wp_upload = wp_upload_dir();
$uploadpath = $wp_upload['path'].'/';
}
$filesave= "select MAX(vid) from ".$wpdb->prefix."hdflv";
$fsquery = mysql_query( $filesave);
$row = mysql_fetch_array($fsquery , MYSQL_NUM);
$destination_path = $uploadpath;
$row1 = $row[0]+1;
$file_name = $row1."_".$_FILES['myfile']['name'];
$target_path = $destination_path ."". $file_name;
if(@move_uploaded_file($file['tmp_name'], $target_path))
{
$errorcode = 0;
}
else
{
$errorcode = 4;
}
sleep(1);
}
//echo $errormsg[$errorcode];
?>
<script language="javascript" type="text/javascript">
window.top.window.updateQueue(<?php echo $errorcode;
?>,"<?php echo $errormsg[$errorcode]; ?>","<?php echo $file_name; ?>");
</script>
Благодаря предварително.