aboutsummaryrefslogtreecommitdiff
path: root/libraries/phpvideotoolkit/examples/php4/example12.php
blob: 8ada5fe4ace95c73cbbd14187942cc239bf71523 (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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php

	/* SVN FILE: $Id$ */
	
	/**
	 * @author Oliver Lillie (aka buggedcom) <publicmail@buggedcom.co.uk>
	 * @package PHPVideoToolkit
	 * @license BSD
	 * @copyright Copyright (c) 2008 Oliver Lillie <http://www.buggedcom.co.uk>
	 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
	 * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
	 * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
	 * is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be
	 * included in all copies or substantial portions of the Software.
	 *
	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
	 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
	 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
	 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	 */

	echo '<html><head><link type="text/css" rel="stylesheet" href="../common/styles.css"><meta name="author" content="Oliver Lillie"></head><body>';
	echo '<a class="backtoexamples" href="../index.php#examples">&larr; Back to examples list</a><br /><br />';
	echo '<strong>This example shows you how to manipulate/format timecode strings.</strong><br /><br />';
	$ignore_demo_files = true;
	
// 	load the examples configuration
	require_once '../example-config.php';
	
// 	require the library
	require_once '../../phpvideotoolkit.'.$use_version.'.php';
	
// 	temp directory
	$tmp_dir = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_PATH.'working'.DS.'tmp'.DS;
	
	
// 	set the time to examine / format
	if(isset($_POST['hours']))
	{
// 		capture timecode and framerate
		$timecode = str_pad(intval($_POST['hours']), 2, '0', STR_PAD_LEFT).':'.str_pad(intval($_POST['mins']), 2, '0', STR_PAD_LEFT).':'.str_pad(intval($_POST['secs']), 2, '0', STR_PAD_LEFT).'.'.str_pad(intval($_POST['millisecs']), 2, '0', STR_PAD_LEFT);
		$frame_rate = intval($_POST['framerate']);
	}
	else
	{
// 		set the frame rate for the timecodes and default time
		$timecode = '01:14:32.59';
		$frame_rate = 25;
	}
	$timecode_format = '%hh:%mm:%ss.%ms';
	
// 		 * 		default '%hh:%mm:%ss'
// 		 * 			- %hh (hours) representative of hours
// 		 * 			- %mm (minutes) representative of minutes
// 		 * 			- %ss (seconds) representative of seconds
// 		 * 			- %fn (frame number) representative of frames (of the current second, not total frames)
// 		 * 			- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
// 		 * 			- %ft (frames total) representative of total frames (ie frame number)
// 		 * 			- %st (seconds total) representative of total seconds (rounded).
// 		 * 			- %sf (seconds floored) representative of total seconds (floored).
// 		 * 			- %sc (seconds ceiled) representative of total seconds (ceiled).
// 		 * 			- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
	
	
// 	start ffmpeg class
	$toolkit = new PHPVideoToolkit($tmp_dir);
	
	echo '<strong>Timecode Format Placeholders</strong><br />';
	echo 'When you format a timecode or format a number of seconds into a timecode you can use the following placeholders to contain different time and frame values<br /><br />';
	echo '<table border="0" cellspacing="0" cellpadding="2">
		<tr>
			<td style="width:50px;border-bottom:1px solid #ccc;">
				<strong>%hh</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				hours
			</td>
		</tr>
		<tr>
			<td>
				<strong>%mm</strong>
			</td>
			<td>
				minutes
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				&nbsp;
			</td>
			<td class="light small" style="border-bottom:1px solid #ccc;">
				NOTE: Smart Value Warning. By default if %hh (hours) aren\'t used in the format then this will give the total number of minutes.
			</td>
		</tr>
		<tr>
			<td>
				<strong>%ss</strong>
			</td>
			<td>
				seconds
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				&nbsp;
			</td>
			<td class="light small" style="border-bottom:1px solid #ccc;">
				NOTE: Smart Value Warning. By default if %hh (hours) or %mm (mins) aren\'t used in the format then this will give the total number of seconds.
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				<strong>%fn</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				frame number
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				<strong>%ms</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				milliseconds
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				<strong>%ft</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				frames total
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				<strong>%st</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				seconds total
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				<strong>%sf</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				seconds floored
			</td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid #ccc;">
				<strong>%sc</strong>
			</td>
			<td style="border-bottom:1px solid #ccc;">
				seconds ceiled
			</td>
		</tr>
		<tr>
			<td>
				<strong>%mt</strong>
			</td>
			<td>
				milliseconds total
			</td>
		</tr>
	</table>';
	echo '<br />';
	echo 'With regards to the Smart Value Warnings, you can turn off smart values by setting the $use_smart_values argument to false when formatting a timecode.<br /><br />';
	
	echo '<strong>Original Timecode</strong><br />';
	echo $timecode.'<br /><br />';
	
	echo '<strong>Timecode conversion to seconds</strong><br />';
	echo 'Frame seconds (rounded) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%st', $frame_rate).'<br />';
	echo 'Frame seconds (rounded down) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%sf', $frame_rate).'<br />';
	echo 'Frame seconds (rounded up) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%sc', $frame_rate).'<br />';
	echo 'Frame seconds -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%mt', $frame_rate).'<br /><br />';
	
	echo '<strong>Timecode conversion to frames</strong><br />';
	echo 'Frame number (in current second) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%fn', $frame_rate).'<br />';
	echo 'Frame number (in video) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%ft', $frame_rate).'<br /><br />';
	
	echo '<strong>Timecode conversion to other timecodes</strong><br />';
	echo 'hh:mm -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm', $frame_rate).'<br />';
	echo 'hh:mm:ss -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm:%ss', $frame_rate).'<br />';
	echo 'hh:mm:ss.fn -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm:%ss.%fn', $frame_rate).'<br />';
	echo 'hh:mm:ss.ms -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm:%ss.%ms', $frame_rate).'<br />';
	echo 'mm:ss (smart minutes) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%mm:%ss', $frame_rate).'<br />';
	echo 'mm:ss.fn (smart minutes) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%mm:%ss.%fn', $frame_rate).'<br />';
	echo 'ss.ms (smart seconds) -> '.$toolkit->formatTimecode($timecode, $timecode_format, '%ss.%ms', $frame_rate).'<br /><br />';
	
 // 	output the timecode form, remembering to disable smart values
	$use_smart_values = false;
	echo '<strong>Change Timecode</strong><br />';
	echo '<form action="example12.php" method="post"><table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td class="small" style="padding-left:4px;">
				Hours
			</td>
			<td class="small" style="padding-left:4px;">
				Mins
			</td>
			<td class="small" style="padding-left:4px;">
				Secs
			</td>
			<td class="small" style="padding-left:4px;">
				Milli
			</td>
			<td class="small" style="padding-left:4px;" colspan="2">
				Frame Rate
			</td>
		</tr>
		<tr>
			<td>
				<input type="text" name="hours" value="'.$toolkit->formatTimecode($timecode, $timecode_format, '%hh', $frame_rate, $use_smart_values).'" id="hours" style="width:35px;margin-right:3px;" />:
			</td>
			<td>
				<input type="text" name="mins" value="'.$toolkit->formatTimecode($timecode, $timecode_format, '%mm', $frame_rate, $use_smart_values).'" id="mins" style="width:35px;margin:0 3px 0 3px;" />:
			</td>
			<td>
				<input type="text" name="secs" value="'.$toolkit->formatTimecode($timecode, $timecode_format, '%ss', $frame_rate, $use_smart_values).'" id="secs" style="width:35px;margin:0 3px 0 3px;" />:
			</td>
			<td>
				<input type="text" name="millisecs" value="'.$toolkit->formatTimecode($timecode, $timecode_format, '%ms', $frame_rate, $use_smart_values).'" id="millisecs" style="width:35px;margin:0 3px 0 3px;" />/
			</td>
			<td>
				<input type="text" name="framerate" value="'.$frame_rate.'" id="framerate" style="width:35px;margin:0 3px 0 3px;" />
			</td>
			<td>
				<input type="submit" value="Update" style="margin:0 0 0 10px;" />
			</td>
		</tr>
</table></form><br />';
	
   echo '</body></html>';