|
阅读:1626回复:2
PHP函数exec()无法调用ffmpeg
该问题在Drupal的flashvideo模块中出现,可能与exec的运行机制有关,直接 exec(”ffmpeg …..”)没有任何输出及结果(可能在某些情况下没问题)。
在 http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2006-October/004773.html 找到答案 使用以下函数代替exec即可 1. /** change exec ($command) to **/
2. runExternal($command, &$code);
3.
4. <?php
5. /** Adding this function to flashvideo.module*/
6. function runExternal( $cmd, &$code ) {
7.
8. $descriptorspec = array(
9. 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
10. 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
11. 2 => array("pipe", "w") // stderr is a file to write to
12. );
13.
14. $pipes= array();
15. $process = proc_open($cmd, $descriptorspec, $pipes);
16.
17. $output= "";
18.
19. if (!is_resource($process)) return false;
20.
21. #close child's input imidiately
22. fclose($pipes[0]);
23.
24. stream_set_blocking($pipes[1],false);
25. stream_set_blocking($pipes[2],false);
26.
27. $todo= array($pipes[1],$pipes[2]);
28.
29. while( true ) {
30. $read= array();
31. if( !feof($pipes[1]) ) $read[]= $pipes[1];
32. if( !feof($pipes[2]) ) $read[]= $pipes[2];
33.
34. if (!$read) break;
35.
36. $ready= stream_select($read, $write=NULL, $ex= NULL, 2);
37.
38. if ($ready === false) {
39. break; #should never happen - something died
40. }
41.
42. foreach ($read as $r) {
43. $s= fread($r,1024);
44. $output.= $s;
45. }
46. }
47.
48. fclose($pipes[1]);
49. fclose($pipes[2]);
50.
51. $code= proc_close($process);
52.
53. return $output;
54. }
55. ?>
原文地址 http://color-magic.cn/?p=15 |
|
|
|
1C#
发布于:2007-05-25 08:58
Re:PHP函数exec()无法调用ffmpeg
深入才发现Drupal插件阵营的强大 |
|
|
|
2C#
发布于:2007-05-24 22:21
Re:PHP函数exec()无法调用ffmpeg
Drupal.............. |
|
|