blob: 021640ba51ff62940170aba4f4635ee7ce045caf (
plain)
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
|
<?php
//$Id$
/*
* @file
* Class file to handle video conversion using ffmpeg and webservices.
*
*/
defined('VIDEO_RENDERING_PENDING') ||
define('VIDEO_RENDERING_PENDING', 1);
defined('VIDEO_RENDERING_ACTIVE') ||
define('VIDEO_RENDERING_ACTIVE', 5);
defined('VIDEO_RENDERING_COMPLETE') ||
define('VIDEO_RENDERING_COMPLETE', 10);
defined('VIDEO_RENDERING_FAILED') ||
define('VIDEO_RENDERING_FAILED', 20);
class video_conversion {
protected $transcoder;
public function __construct() {
module_load_include('inc', 'video', '/includes/transcoder');
$this->transcoder = new video_transcoder;
}
/**
* Our main function to call when converting queued up jobs.
*/
public function run_queue() {
if ($videos = $this->load_job_queue()) {
foreach ($videos as $video) {
$this->process($video);
}
//clear cache once completed the conversion to update the file paths
cache_clear_all('*', 'cache_content', true);
}
}
/**
* Select videos from our queue
*
* @return
* An array containing all the videos to be proccessed.
*/
private function load_job_queue() {
// @TODO : allow only limited jobs to process
return $this->transcoder->load_job_queue();
}
/**
* Process the video through ffmpeg.
*
* @param $video
* This can either be the file object or the file id (fid)
*
* @return
* TRUE of FALSE if video was converted successfully.
*/
public function process($video) {
if (is_object($video) && isset($video->fid)) {
$return = $this->render($video);
} else {
$video_object = $this->load_job($video);
$return = $this->render($video_object);
}
return $return;
}
private function render($video) {
if (!is_object($video)) {
watchdog('video_conversion', 'Video object is not present', array(), WATCHDOG_ERROR);
return FALSE;
}
// Make sure this video is pending or do nothing.
if ($video->video_status == VIDEO_RENDERING_PENDING) {
return $this->transcoder->convert_video($video);
}
return NULL;
}
/**
* Load a converted video based on the file id ($fid)
*
* @todo: Need to figure something out here for multiple files (HTML 5)
* @param $fid
* Integer of the file id to be loaded.
*/
public function load_completed_job($video) {
return $this->transcoder->load_completed_job($video);
}
public function create_job($video) {
return $this->transcoder->create_job($video);
}
public function update_job($video) {
return $this->transcoder->update_job($video);
}
public function delete_job($video) {
return $this->transcoder->delete_job($video);
}
/**
* Load a file based on the file id ($fid)
*
* @param $fid
* Integer of the file id to be loaded.
*/
public function load_job($fid) {
return $this->transcoder->load_job($fid);
}
}
?>
|