php exec()适用于某些调用,而不是其他类似调用

php exec()适用于某些调用,而不是其他类似调用

问题描述:

I have a php script that cuts up video. Here are three exec() commands - two execute properly while one does not:

Works:

sudo ffmpeg -i /home/vidserver/videos/$filename.mp4 -ss $ctime -t 00:00:06 -acodec copy -vcodec copy -y /var/vidcache/test$x.mp4

Works:

sudo ffmpeg -i /var/vidcache/test$x.mp4 -qscale:v 1 /var/vidcache/i$x.mpg

Does not work:

sudo ffmpeg -i concat:"i0.mpg|i1.mpg" -qscale:v 1 /var/vidcache/output.mpg

/var/vidcache has 777 privs and www-data is in the sudoers file with NOPASSWD (yes, I know - this is just for debug purposes before I lock down security).

When I run the last command from a php script from the command line by itself, it DOES work. (Running as www-data or root.) But when I try to put it in a function called from a web page, it does NOT work.

Any ideas?

我有一个用于剪切视频的php脚本。 这里有三个exec()命令 - 两个执行正确而一个不执行: p>

Works: p>

sudo ffmpeg -i / home / vidserver / videos / $ filename.mp4 -ss $ ctime -t 00:00:06 -acodec copy -vcodec copy -y /var/vidcache/test$x.mp4 p> blockquote> \ n

Works: p>

sudo ffmpeg -i /var/vidcache/test$x.mp4 -qscale:v 1 / var / vidcache / i $ x.mpg p> blockquote>

不起作用: p>

sudo ffmpeg -i concat: “i0.mpg | i1.mpg” -qscale:v 1 /var/vidcache/output.mpg

nn

/var/vidcache有777个私人和 www-data code>在带有NOPASSWD的sudoers文件中(是​​的,我知道 - 在锁定安全性之前,这仅用于调试目的)。 p>

当我从命令行单独运行php脚本中的最后一个命令时,它就可以工作了。 (以www-data或root身份运行。)但是当我尝试将它放在从网页调用的函数中时,它不起作用。 p>

任何想法? p> \ n div>

Actually, the answer was as stupid as "where does www-data know where to look for files?"

I was assuming a lot with the i0.mpg. It needs a fully qualified directory, obviously.

Anyway, changing the code to look like this worked:

sudo ffmpeg -i concat:"/var/vidcache/i0.mpg|/var/vidcache/i1.mpg" -qscale:v 1 /var/vidcache/output.mpg

This should fix the third exec:

sudo ffmpeg -i "concat:i0.mpg|i1.mpg" -qscale:v 1 /var/vidcache/output.mpg

Here is a good wiki page on how to concat media files in ffmpeg.