9

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

jq beginner
  • 1,010
  • 3
  • 21
  • 41

2 Answers2

13

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.

Tony
  • 1,811
  • 1
  • 20
  • 27
  • thanks for answering but still don't understand - how to upload ffmpeg to the server and install it using this code i don't know anything about linux and i'm new to hosting i have cpanel 11.30.5 (build 6) – jq beginner Jan 29 '12 at 13:06
  • ok i asked hosting support and they got back to me that ffmpeg is not supported any solution ? – jq beginner Jan 29 '12 at 13:14
  • If your hosting company doesn't have ffmpeg installed, then unfortunately this solution will not work for you. Can you switch to a hosting that does support ffmpeg? Do a Google search on `shared hosting ffmpeg`. There should be hundreds of them around. – Tony Jan 29 '12 at 17:54
3

Or you can do it in the browser with HTML5's video tag and canvas, see: https://gist.github.com/adamjimenez/5917897

Adam Jimenez
  • 3,085
  • 3
  • 35
  • 32
  • 1
    Should be the answer. Ffmpeg kinda sucks for this small task. Wasted planty of time on it. – M H Apr 10 '15 at 05:36
  • that's what i use. after upload is finished, client generates the thumbnail and gives base64 data to the server. great anwser –  Oct 06 '15 at 10:59