1:
2:
<?php
3:
4:
function convert_video($source, $format, $ffmpeg, $quality, $width, $height, $bitrate, $channel, $rate, $screenshot, $seek, $pic_w, $pic_h) {
5:
6:
$screen = $width .'x'. $height;
7:
$pic_size = $pic_w .'x'. $pic_h;
8:
$seek = date("H:i:s", strtotime("00:00:00 +$seek seconds"));
9:
$destination = preg_replace('/\.[a-z]{2,4}$/', '', $source);
10:
11:
$cmd = "-qscale $quality -s $screen -ab $bitrate -ac $channel -ar $rate";
12:
13:
// konvertera rullen...
14:
exec("START $ffmpeg/ffmpeg -i $source $cmd {$destination}.$format");
15:
16:
// kontrollera så att den konverterade filen verkligen finns...
17:
if (file_exists("{$destination}.$format")) {
18:
// Ta en screendump av filmen och spara som png
19:
if ($screenshot) {
20:
exec("START $ffmpeg/ffmpeg -i $source -vcodec png -ss $seek -s {$pic_size} -vframes 1 {$destination}_%d.png");
21:
$screen = $destination . "_1.png";
22:
} else {
23:
$screen = false;
24:
}
25:
return array('video' => "{$destination}.$format", 'screen' => $screen);
26:
} else {
27:
return false;
28:
}
29:
}
30:
31:
if (isset($_POST['submit'])) {
32:
$movie = $_FILES['movie']['name'];
33:
$path = "videoclips/$movie"; // vart ska filmen sparas?
34:
//$res = move_uploaded_file($_FILES['movie']['tmp_name'], $path);
35:
//echo $res;
36:
// Flytta rullen till $path
37:
if(move_uploaded_file($_FILES['movie']['tmp_name'], $path)) {
38:
$type = 'flv'; // format att konvertera till
39:
$ffmpeg = 'ffmpeg'; // Sökväg till mappen där ffmpeg ligger
40:
$q = 10; // Kvalité på konverteringen (0=bäst, 31=sämst)
41:
$w = 320; // Bredd i px
42:
$h = 240; // Höjd i px
43:
$b = 96; // Kvalite på ljudet: 96 kb/s
44:
$c = 1; // Kanaler (1=mono, 2=stereo)
45:
$r = 44100; // Samples per sekund
46:
$s = true; // Ta screenshot? (boolean)
47:
$t = 3; // hur många sekunder in i filmen ska screenshot´en tas?
48:
$s_w = 120; // screenshot-bredd i px
49:
$s_h = 90; // screenshot-höjd i px
50:
$convert = convert_video($path, $type, $ffmpeg, $q, $w, $h, $b, $c, $r, $s, $t, $s_w, $s_h);
51:
// Lyckades konverteringen?
52:
if ($convert) {
53:
$msg = "<img src=\"$convert[screen]\" alt=\"\" /><br />
54:
<a href=\"$convert[video]\">". basename($convert['video']) ."</a> - Hårdrock, allt ok!";
55:
} else {
56:
$msg = "Något gick fel!";
57:
}
58:
// Radera den uppladdade filmen
59:
unlink($path);
60:
} else {
61:
$msg = "A problem occured while uploading $movie!";
62:
}
63:
echo $msg;
64:
}
65:
?>
66:
67:
<form method="post" action="" enctype="multipart/form-data">
68:
<input type="file" name="movie" /><br />
69:
<input type="submit" name="submit" value="Upload Clip!" />
70:
</form>
71: