Fed*_*cci 1 php imagemagick shell-exec
我必须使用 Fred 的 ImageMagick 脚本创建图像的过渡序列,特别是fx 过渡。
在我的 php 代码中,我将所有图像调整为标准尺寸,然后将所有这些图片重命名为 pic000001.jpg、pic000002.jpg、pic000003.jpg 等(我用 $count 进行计数),然后我愿意:
$frameIndex=0;
$frames=18;
//for all the pic000001.jpg, pic000002.jpg, pic000003.jpg.... do a transition
//between them
for($seq=1;$seq<$count;$seq++){
//here I take a picture and the next(IE pic000001 and pic000002)
echo shell_exec("fxtransitions -e swirl -f $frames -d 20 -p 50 $path/pic".str_pad($seq, 6, '0', STR_PAD_LEFT).".jpg $path/pic".str_pad(($seq+1), 6, '0', STR_PAD_LEFT).".jpg $path/fx%06d.jpg");
//here I rename the temporany frames called
//fx000000.jpg to fx000035.jpg for each transition
//to a common index
for($c=0;$c<($frames*2);$c++){
rename("fx".str_pad($c, 6, '0', STR_PAD_LEFT).".jpg" ,str_pad($frameIndex, 6, '0', STR_PAD_LEFT).".jpg");
$frameIndex++;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用 FFMpeg 组合所有帧并制作视频。问题是 fxtransition 提示错误:
--- FILE DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---
Run Code Online (Sandbox Code Playgroud)
(这肯定是由脚本生成的消息),后面是这样的消息:
Warning: rename(fx000000.jpg,000000.jpg): No such file or directory in /var/www/html/TEST/APP/generateVideo.php on line 168
Run Code Online (Sandbox Code Playgroud)
因为图片没有生成(它表明帧编号的算法是正确的,所以不要关注这一点)。
如果我使用 ssh 连接打开服务器上的终端并运行该命令,它会给出相同的错误,除非我使用 sudo。如果我在 php shell_exec 上使用 sudo,它不会执行。shell_exec('whoami') 返回 apache,apache 是我在这些函数中涉及的所有文件夹和文件的所有者。
请帮忙吗?如果您有 Fred 的 imagemagick 脚本的替代方案来生成过渡帧来生成视频,我们也将不胜感激。
小智 5
我在使用 Fred 的 ImageMagick 脚本之一时遇到了这个问题。解决方案是使用您最喜欢的编辑器(vim、nano 等)更新脚本文件 (scriptname.sh) 并设置正确的临时目录。见下文:
# set directory for temporary files
dir="." # suggestions are dir="." or dir="/tmp"
#
Run Code Online (Sandbox Code Playgroud)
就我而言,临时目录是“/tmp”
# set directory for temporary files
dir="/tmp" # suggestions are dir="." or dir="/tmp"
#
Run Code Online (Sandbox Code Playgroud)