Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash imagemagick以gif格式转换单个帧延迟_Bash_Imagemagick_Animated Gif - Fatal编程技术网

Bash imagemagick以gif格式转换单个帧延迟

Bash imagemagick以gif格式转换单个帧延迟,bash,imagemagick,animated-gif,Bash,Imagemagick,Animated Gif,我有一个目录,里面满是我想转换成gif格式的图像 每个文件名都遵循以下模式:\uuu0.gif 示例:00001\u 1432.gif 我可以使用imagemagick创建gif动画:convert-loop 0-delay 10*.gif out.gif 问题是,我希望每一帧都有一个不同的延迟,基于其名称中的第二个数字 convert -delay 0 -loop 0 *.gif output.gif for gif in *.gif; do name=${gif%.gif}

我有一个目录,里面满是我想转换成gif格式的图像

每个文件名都遵循以下模式:
\uuu0.gif

示例:
00001\u 1432.gif

我可以使用imagemagick创建gif动画:
convert-loop 0-delay 10*.gif out.gif

问题是,我希望每一帧都有一个不同的延迟,基于其名称中的第二个数字

convert -delay 0 -loop 0 *.gif output.gif

for gif in *.gif; do

    name=${gif%.gif}
    index=$(echo ${name%-*} | sed 's/0*//')
    delay=${name#*-}

    # 1. convert milliseconds to w/e imagemagick -delay uses.
    # 2. update the frame at the correct index.

done;
我是否以增量方式构建gif?还是事后回去换?
我的照片不符合标准。

< P>所以,如果我正接近这个问题,我会做以下(如果我理解正确)

给定以下文件:

[root@dev7 ~]# ls -lta so/
total 728
drwxr-xr-x   2 root root   4096 Aug 13 18:35 .
dr-xr-x---. 17 root root   4096 Aug 13 18:35 ..
-rw-r--r--   1 root root  18933 Aug 13 18:23 00007_1432.gif
-rw-r--r--   1 root root  18594 Aug 13 18:23 00006_1432.gif
-rw-r--r--   1 root root  18984 Aug 13 18:23 00005_1432.gif
-rw-r--r--   1 root root  19601 Aug 13 18:23 00004_1444.gif
-rw-r--r--   1 root root  19408 Aug 13 18:23 00003_1432.gif
-rw-r--r--   1 root root  18632 Aug 13 18:23 00002_1552.gif
-rw-r--r--   1 root root  20104 Aug 13 18:23 00001_1432.gif
[root@dev7 ~]# 
我的脚本如下所示:

#!/bin/bash -x

# directory of the individual gifs
_dir=/root/so/

# get gifs and make sure your sort them in order
gifs=$(find $_dir -name *.gif|sort|xargs)

# this is going to be the imagemagick command
_CONVERT="convert "

# make sure the list of gifs look correct
echo $gifs

for gif in $gifs; do

    # full path of each gif
    full_path=$gif

    # get just the name of the gif ( originally I was going to use this if everything was happing within the same directory )
    name=$(echo ${gif##*/})
    #echo -e "\n$name"

    # Get the index
    index=$(echo ${gif##*/} | cut -d\_ -f1)
    #echo -e "\n$index"

    # Get the delay of the current image
    delay=$(echo ${gif##*/} | cut -d\_ -f2| sed "s,.gif,,")
    # echo -e "\n$delay"

    # add correct delay options to current gif, append to existing command
   _CONVERT="${_CONVERT} -delay $delay $gif " 

done;

# add the outpt of where you're going to put your gif
_CONVERT="${_CONVERT} -loop 0 -layers Optimize /root/so/stackoverflow.gif"

# show full command
echo "Convert cmd: $_CONVERT"

# run it, then go get your image
eval $_CONVERT
生成的命令示例:

Convert cmd: convert  -delay 1432 /root/so/00001_1432.gif  -delay 1552 /root/so/00002_1552.gif  -delay 1432 /root/so/00003_1432.gif  -delay 1444 /root/so/00004_1444.gif  -delay 1432 /root/so/00005_1432.gif  -delay 1432 /root/so/00006_1432.gif  -delay 1432 /root/so/00007_1432.gif  -layers Optimize /root/so/stackoverflow.gif

希望这就是您想要的。

,您可以使用globbing来代替:
用于*.gif中的gif\u文件;做[…];完成
。同时引用你的变量<代码>剪切也不需要,您可以对同一任务使用参数替换。感谢脚本。我在查找中出错,我必须添加引号。比照。啊,报价绝对是关键!谢谢你,马努!