22
33 include_once './includes/bootstrap.php ' ;
44
5+ echo '<a href="?method=blocking">Blocking</a> | <a href="?method=non-blocking">Non blocking</a><br /> ' ;
6+
57 try
68 {
79 $ video = new \PHPVideoToolkit \Video ($ example_video_path , $ config );
10+ $ video ->extractSegment (new \PHPVideoToolkit \Timecode (10 ), new \PHPVideoToolkit \Timecode (70 ));
811 $ process = $ video ->getProcess ();
912
10- $ progress_handler = new \ PHPVideoToolkit \ ProgressHandlerOutput ( function ( $ data )
13+ if ( isset ( $ _GET [ ' method ' ]) === true && $ _GET [ ' method ' ] === ' blocking ' )
1114 {
12- // echo '<pre>'.print_r($data, true).'</pre>';
13- // do something here...
14- // IMPORTANT NOTE: most modern browser don't support output buffering any more.
15- }, $ config );
16-
17- /*
18- ...or...
15+ echo '<h2>Blocking Method</h2> ' ;
1916
20- $progress_handler = new ProgressHandlerOutput(null, $config);
17+ // If you use a blocking save but want to handle the progress during the block, then assign a callback within
18+ // the constructor of the progress handler.
19+ // IMPORTANT NOTE: most modern browser don't support output buffering any more.
20+ $ progress_data = array ();
21+ $ progress_handler = new \PHPVideoToolkit \ProgressHandlerOutput (function ($ data ) use (&$ progress_data )
22+ {
23+ // do something here like log to file or db.
24+ array_push ($ progress_data , round ($ data ['percentage ' ], 2 ).': ' .round ($ data ['run_time ' ], 2 ));
25+ }, $ config );
2126
22- ...then after a call to saveNonBlocking...
23-
24- while($progress_handler->completed !== true)
25- {
26- // note setting true in probe() automatically tells the probe to wait after the data is returned.
27- echo '<pre>'.print_r($progress_handler->probe(true), true).'</pre>';
28- }
29-
30- */
27+ $ output = $ video ->purgeMetaData ()
28+ ->setMetaData ('title ' , 'Hello World ' )
29+ ->save ('./output/big_buck_bunny.3gp ' , null , \PHPVideoToolkit \Video::OVERWRITE_EXISTING , $ progress_handler );
30+
31+ array_unshift ($ progress_data , 'Percentage Completed: Time taken ' );
32+ \PHPVideoToolkit \Trace::vars (implode (PHP_EOL , $ progress_data ));
33+ }
34+ else
35+ {
36+ echo '<h2>Non Blocking Method</h2> ' ;
3137
32- $ output = $ video ->purgeMetaData ()
33- ->setMetaData ('title ' , 'Hello World ' )
34- ->save ('./output/big_buck_bunny.3gp ' , null , \PHPVideoToolkit \Video::OVERWRITE_EXISTING , $ progress_handler );
38+ // use a non block save to probe the progress handler after the save has been made.
39+ // IMPORTANT: this method only works with ->saveNonBlocking as otherwise the progress handler
40+ // probe will quit after one cycle.
41+ $ progress_handler = new \PHPVideoToolkit \ProgressHandlerOutput (null , $ config );
42+ $ output = $ video ->purgeMetaData ()
43+ ->setMetaData ('title ' , 'Hello World ' )
44+ ->saveNonBlocking ('./output/big_buck_bunny.3gp ' , null , \PHPVideoToolkit \Video::OVERWRITE_EXISTING , $ progress_handler );
3545
46+ while ($ progress_handler ->completed !== true )
47+ {
48+ \PHPVideoToolkit \Trace::vars ($ progress_handler ->probe (true , 1 ));
49+ }
50+ }
51+
3652 echo '<h1>Executed Command</h1> ' ;
3753 \PHPVideoToolkit \Trace::vars ($ process ->getExecutedCommand ());
3854 echo '<hr /><h1>FFmpeg Process Messages</h1> ' ;
7086 \PHPVideoToolkit \Trace::vars ($ e );
7187
7288 echo '<a href="?reset=1">Reset Process</a> ' ;
73- }
89+ }
0 commit comments