-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathtranscoder_video.php
189 lines (159 loc) · 7.82 KB
/
transcoder_video.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCoreSamples Samples
* @{
*/
/**
* @page samples
* @section transcoder_videos Transcoder Videos
*
* This sample shows how transcoder can be used for video files.
*
* @code
CREATE TABLE `sample_transcoder_video_orig` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`profile_id` int(10) unsigned NOT NULL,
`remote_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`path` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`file_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mime_type` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`ext` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`size` int(11) NOT NULL,
`added` int(11) NOT NULL,
`modified` int(11) NOT NULL,
`private` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `remote_id` (`remote_id`)
);
INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES
('sample_transcoder_video_orig', 'Local', '', 360, 2592000, 0, 'sample_transcoder_video_orig', 'allow-deny', 'avi,flv,mpg,mpeg,wmv,mp4,m4v,mov,qt,divx,xvid,3gp,3g2,webm,mkv,ogv,ogg,rm,rmvb,asf,drc', '', 0, 0, 0, 0, 0, 0);
CREATE TABLE `sample_transcoder_video` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`profile_id` int(10) unsigned NOT NULL,
`remote_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`path` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`file_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mime_type` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`ext` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`size` int(11) NOT NULL,
`added` int(11) NOT NULL,
`modified` int(11) NOT NULL,
`private` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `remote_id` (`remote_id`)
);
INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES
('sample_transcoder_video', 'Local', '', 360, 2592000, 0, 'sample_transcoder_video', 'allow-deny', 'avi,flv,mpg,mpeg,wmv,mp4,m4v,mov,qt,divx,xvid,3gp,3g2,webm,mkv,ogv,ogg,rm,rmvb,asf,drc,jpg', '', 0, 0, 0, 0, 0, 0);
INSERT INTO `sys_objects_transcoder` (`object`, `storage_object`, `source_type`, `source_params`, `private`, `atime_tracking`, `atime_pruning`, `ts`, `override_class_name`, `override_class_file`) VALUES
('sample_video_poster', 'sample_transcoder_video', 'Storage', 'a:1:{s:6:"object";s:28:"sample_transcoder_video_orig";}', 'no', 0, 0, 0, 'BxDolTranscoderVideo', ''),
('sample_video_mp4', 'sample_transcoder_video', 'Storage', 'a:1:{s:6:"object";s:28:"sample_transcoder_video_orig";}', 'no', 0, 0, 0, 'BxDolTranscoderVideo', ''),
('sample_video_webm', 'sample_transcoder_video', 'Storage', 'a:1:{s:6:"object";s:28:"sample_transcoder_video_orig";}', 'no', 0, 0, 0, 'BxDolTranscoderVideo', '');
INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_params`, `order`) VALUES
('sample_video_webm', 'Webm', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:4:"webm";}', 0),
('sample_video_mp4', 'Mp4', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"mp4";}', 0),
('sample_video_poster', 'Poster', 'a:2:{s:1:"h";s:3:"480";s:10:"force_type";s:3:"jpg";}', 0);
* @endcode
*
*/
require_once('./../inc/header.inc.php');
require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
$oTemplate = BxDolTemplate::getInstance();
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageHeader ("Sample video transcoder");
$oTemplate->setPageContent ('page_main_code', PageCompMainCode());
$oTemplate->getPageCode();
/**
* page code function
*/
function PageCompMainCode()
{
ob_start();
$sTranscoderObjectPoster = 'sample_video_poster';
$sTranscoderObjectMP4 = 'sample_video_mp4';
$sTranscoderObjectWebM = 'sample_video_webm';
$sStorageObjectOrig = 'sample_transcoder_video_orig';
$iProfileId = bx_get_logged_profile_id();
if (!$iProfileId) {
echo "You aren't logged in.";
exit;
}
$iPrunedFiles = BxDolTranscoder::pruning();
if ($iPrunedFiles) {
echo "iPrunedFiles: $iPrunedFiles";
exit;
}
$oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($sTranscoderObjectPoster);
$oTranscoderMP4 = BxDolTranscoderVideo::getObjectInstance($sTranscoderObjectMP4);
$oTranscoderWebM = BxDolTranscoderVideo::getObjectInstance($sTranscoderObjectWebM);
if (!$oTranscoderPoster || !$oTranscoderMP4 || !$oTranscoderWebM) {
echo "Transcoder object is not available: " . $sTranscoderObjectPoster . ', ' . $sTranscoderObjectMP4 . ', ' . $sTranscoderObjectWebM;
exit;
}
echo "registerHandlers poster: [" . $oTranscoderPoster->registerHandlers() . "] <br />\n";
echo "registerHandlers mp4: [" . $oTranscoderMP4->registerHandlers() . "] <br />\n";
echo "registerHandlers webm: [" . $oTranscoderWebM->registerHandlers() . "] <hr class='bx-def-hr' />\n";
$oStorageOrig = BxDolStorage::getObjectInstance($sStorageObjectOrig);
if (!$oStorageOrig) {
echo "Storage object is not available: " . $sStorageObjectOrig;
exit;
}
if (isset($_POST['upload'])) {
$iId = $oStorageOrig->storeFileFromForm($_FILES['file'], true, $iProfileId);
if ($iId) {
$iCount = $oStorageOrig->afterUploadCleanup($iId, $iProfileId);
echo "<h2>Uploaded file id: " . $iId . "(deleted ghosts:" . $iCount . ") </h2>";
// force transcode
echo "Force transcode: <br />";
echo "poster: " . $oTranscoderPoster->getFileUrl($iId) . '<br />';
echo "mp4: " . $oTranscoderMP4->getFileUrl($iId) . '<br />';
echo "webm: " . $oTranscoderWebM->getFileUrl($iId) . '<hr class="bx-def-hr" />';
} else {
echo "<h2>Error uploading file: " . $oStorage->getErrorString() . '</h2><hr class="bx-def-hr" />';
}
}
elseif (isset($_POST['delete'])) {
foreach ($_POST['file_id'] as $iFileId) {
$bRet = $oStorageOrig->deleteFile($iFileId, $iProfileId);
if ($bRet)
echo "<h2>Deleted file id: " . $iFileId . '</h2><hr class="bx-def-hr" />';
else
echo "<h2>File deleting error: " . $oStorageOrig->getErrorString() . '</h2><hr class="bx-def-hr" />';
}
}
else {
$a = $oStorageOrig->getFilesAll();
foreach ($a as $r) {
$sUrlPoster = $oTranscoderPoster->getFileUrl($r['id']);
$sUrlMP4 = $oTranscoderMP4->getFileUrl($r['id']);
$sUrlWebM = $oTranscoderWebM->getFileUrl($r['id']);
echo '<h3>' . $r['file_name'] . '</h3>';
echo BxTemplFunctions::getInstance()->videoPlayer($sUrlPoster, $sUrlMP4, $sUrlWebM, false, 'height:200px;');
echo '<hr class="bx-def-hr" />';
}
}
$a = $oStorageOrig->getFilesAll();
?>
<h2>Files List</h2>
<form method="POST">
<?php foreach ($a as $r): ?>
<input type="checkbox" name="file_id[]" value="<?=$r['id'] ?>" />
<?=$r['file_name'] ?>
<br />
<?php endforeach; ?>
<input type="submit" name="delete" value="Delete" class="bx-btn bx-btn-small bx-def-margin-sec-top" style="float:none;" />
</form>
<hr class="bx-def-hr" />
<h2>Upload</h2>
<form enctype="multipart/form-data" method="POST">
<input type="file" name="file" />
<br />
<input type="submit" name="upload" value="Upload" class="bx-btn bx-btn-small bx-def-margin-sec-top" style="float:none;" />
</form>
<?php
$s = ob_get_clean();
return DesignBoxContent("Sample video transcoder", $s, BX_DB_PADDING_DEF);
}
/** @} */