需要为视频上传创建缩略图(非常简单的代码) [英] need to create thumbnail for video uploading (very simple code)

查看:309
本文介绍了需要为视频上传创建缩略图(非常简单的代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个页面(很简单,显示我需要)上传flv文件 - 我读了一些关于ffmpeg-php的文章,但是如何在服务器上安装如果是解决方案和如何使用它?

 <?php 
if(isset($ _ REQUEST ['upload'])){
$ tmp_name = $ _FILES [ '视频'] [ 'tmp_name的值'];
$ name = $ _FILES ['video'] ['name'];
$ path =videos /;
move_uploaded_file($ tmp_name,$ path。$ name);
}
else {
?>
< form action =method =postenctype =multipart / form-data>
< input name =videotype =file/> < input name =uploadtype =submitvalue =upload/>
< / form>
<?php
}
?>

并且需要为其他文件夹中上传的同名视频创建缩略图
任意帮帮我 ?在此先感谢

解决方案

安装ffmpeg应该很简单。在任何基于Ubuntu / Debian的发行版中,使用apt-get:

  apt-get install ffmpeg 

之后,您可以使用它创建缩略图。

首先,您需要从文件中获取随机时间位置:

  $ video = $ path。 escapeshellcmd($ _ FILES [视频] [名称]); 
$ cmd =ffmpeg -i $ video 2>& 1;
$ second = 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));

$ / code>

现在你的 $ second 变量被设置。获取实际缩略图:

  $ image ='thumbnails / random_name.jpg'; 
$ cmd =ffmpeg -i $ video -deinterlace -an -ss $ second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $ image 2>& 1;
$ do =`$ cmd`;

它会自动将缩略图保存到 thumbnails / random_name.jpg (您可以根据上传的视频更改该名称)



如果要调整缩略图大小,请使用 - 参数( -s 300x300



查看ffmpeg文档,查看可以使用的参数的完整列表。


i have this page (very simple to show what i need) to upload flv files - i read some posts about ffmpeg-php but how to install in on the server if it's the solution and how to use it?

<?php
if(isset($_REQUEST['upload'])){
$tmp_name = $_FILES['video']['tmp_name'];
$name = $_FILES['video']['name'];
$path = "videos/";
move_uploaded_file($tmp_name,$path.$name);
}
else{
?>
<form action="" method="post" enctype="multipart/form-data">
<input name="video" type="file" /> <input name="upload" type="submit" value="upload" />
</form>
<?php
}
?>

and need to create a thumbnail for video uploaded in another folder with the same name any help ? thanks in advance

解决方案

Installing ffmpeg should be straightforward. On any Ubuntu/Debian based distro, use apt-get:

apt-get install ffmpeg

After that, you can use it to create a thumbnail.

First you need to get a random time location from your file:

$video = $path . escapeshellcmd($_FILES['video']['name']);
$cmd = "ffmpeg -i $video 2>&1";
$second = 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));
}

Now that your $second variable is set. Get the actual thumbnail:

$image  = 'thumbnails/random_name.jpg';
$cmd = "ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";
$do = `$cmd`;

It will automatically save the thumbnail to thumbnails/random_name.jpg (you may want to change that name based on the uploaded video)

If you want to resize the thumbnail, use the -s parameter (-s 300x300)

Check out the ffmpeg documentation for a complete list of parameters you can use.

这篇关于需要为视频上传创建缩略图(非常简单的代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆