消除ffmpeg和image-magic命令中的慢速因素 [英] Eliminate slow speed factor in ffmpeg and image-magic commands

查看:96
本文介绍了消除ffmpeg和image-magic命令中的慢速因素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些命令的基本思想是创建一个比较,(比较从过去定义了一个jpeg,从现在定义了一个jpeg,将它们组合在一起,例如它们将彼此滑动并在图像之后显示.)

The basic idea of these commands is to create a compare, (A compare has defined a jpeg from past and one from the present, combine such as they will slide on each other and show before after images.)

例如 https://media.evercam.io/v1/摄影机/1lowe-scnoe/compares/lower-jreyh.gif

所有命令都写在下面,进行这些操作

All the commands are written below, doing these operations

  • 在图像后调整大小.
  • 使用两个图像创建一个Gif.
  • 将日志添加到Gif.
  • 从GIF创建一个MP4文件.
  • 从mp4文件创建缩略图.

徽标为:

我们正在使用FFmpeg和ImageMagick命令(例如

we are making animation and mp4 files using FFmpeg and ImageMagick commands such as

ffmpeg -i before_image.jpg -s 1280x720 before_image_resize.jpg

ffmpeg -i after_image.jpg -s 1280x720 after_image_resize.jpg

以上命令首先要调整将在动画中使用的两个图像的大小.

The above commands are first to resize both images which are going to be used in animation.

此命令用于创建gif.

This command is being used for creating a gif.

convert after_image_resize.jpg before_image_resize.jpg -write mpr:stack -delete 0--1 mpr:stack'[1]' \\( mpr:stack'[0]' -set delay 25 -crop 15x0 -reverse \\) mpr:stack'[0]' \\( mpr:stack'[1]' -set delay 27 -crop 15x0 \\) -set delay 2 -loop 0 temp.gif

此命令可将徽标添加到动画中.

This command to add a logo to the animation.

convert temp.gif -gravity SouthEast -geometry +15+15 null: evercam-logo.png -layers Composite compa-efxfphu.gif

然后将mp4文件创建为

Then to create an mp4 file as

ffmpeg -f gif -i compa-efxfphu.gif -pix_fmt yuv420p -c:v h264_nvenc -movflags +faststart -filter:v crop='floor(in_w/2)*2:floor(in_h/2)*2' compa-efxfphu.mp4

然后从此mp4创建缩略图.

then to create a thumbnail from this mp4.

ffmpeg -i compa-efxfphu.mp4 -vframes 1 -vf scale=640:-1 -y thumb-compa-efxfphu.jpg

是否有可能减少这些步骤?这一切都花费很多时间,我只对两个convert命令都感兴趣,我们可以将它们组合成一个命令吗?

Is there any possibility to reduce any of these steps? This all takes a lot of time, I am merely interested in both convert commands, can we make them into one command?

或者您是否有机会将所有这4项合计减少?任何输入都会非常感激.

Or do you see any chance to reduce these all 4 in one? any input will be so thankful.

推荐答案

更新后的答案

这是我最好的镜头,它的运行时间约为原始答案的50%...

Here is my best shot at this, it runs in about 50% of the time of the original answer...

convert -depth 8 -gravity southeast -define jpeg:size=1280x720   \
   logo.png   -write MPR:logo +delete                            \
   \( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \)   \
   \( after.jpg  -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after  \)   \
   +append -quantize transparent -colors 250 -unique-colors +repage -write MPR:commonmap +delete \
   MPR:after  -map MPR:commonmap +repage -write MPR:after  +delete \
   MPR:before -map MPR:commonmap +repage -write MPR:before         \
              \( MPR:after -set delay 25 -crop 15x0 -reverse \)    \
   MPR:after  \( MPR:before -set delay 27 -crop 15x0         \)    \
   -set delay 2 -loop 0 -write anim.gif                            \
   -delete 1--1 -resize 640x thumb.jpg

这是我的想法...

  • 像使用JPEG一样将深度设置为8,设置gravity并初始化libjpeg负载收缩" 功能,
  • 加载徽标并保存到MPR,因为我们将使用它两次,
  • (...)内启动一些旁处理" 以加载before图片,调整其大小,粘贴徽标并保存到MPR以供以后使用,
  • 重复after图片的上一步,
  • 将前后图像附加在一起,并计算出适合两者的组合色彩图,并保存它,
  • 将图像前后的图像映射到新的组合色图,
  • 删除所有垃圾邮件,
  • 一种动画方式,
  • 为另一个动画,
  • 使动画永无止境,并将动画保存到GIF,
  • 删除第一帧以外的所有内容,调整其大小并另存为缩略图.
  • set the depth to 8 as we are using JPEG, set gravity and initialise libjpeg's "shrink-on-load" feature,
  • load the logo and save to MPR as we will be using it twice,
  • start some "aside processing" inside (...) to load the before image, resize it, paste on the logo and save to MPR for later use,
  • repeat previous step for the after image,
  • append the before and after images together and calculate a combined colormap suitable for both and save it,
  • map both before and after images to new, combined colormap,
  • delete all junk,
  • animate one way,
  • animate the other,
  • make animation endless, and save animation to GIF,
  • delete all except first frame, resize that and save as thumbnail.

原始答案

仍在进行中,但您可以避免调用ffmpeg的前两次,并在 ImageMagick 中进行大小调整,还可以将徽标一次粘贴到顶部:

Still a work in progress, but you can avoid the first two invocations of ffmpeg and do the resizing within ImageMagick, and also paste the logos on top in one go like this:

convert -gravity southeast logo.png  -write MPR:logo \
  \( before.jpg -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:before \) \
  \( after.jpg  -resize '1280x720!' MPR:logo -geometry +15+15 -composite -write MPR:after  \) \
  -delete 0--1                                           \
  MPR:before  \( MPR:after  -set delay 25 -crop 15x0 -reverse     \) \
  MPR:after   \( MPR:before -set delay 27 -crop 15x0   \) \
  -set delay 2 -loop 0 temp.gif


如果您将以下行的最后一行更改为:


You can probably also create the thumbnail with that command too, if you change the last line from:

-set delay 2 -loop 0 temp.gif

-set delay 2 -loop 0 -write temp.gif \
-delete 1--1 -resize 640x thumbnail.jpg


您还可以使用libjpeg的加载时收缩" 功能来加快速度并减少内存使用.基本上,您在读取磁盘之前告诉它所需的文件大小,并且它仅读取文件的一个子集,从而减少了I/O时间和内存压力:


You can also speed things up and reduce memory usage by using libjpeg's "shrink-on-load" feature. Basically, you tell it before reading the disk how big a file you need and it only reads a subset of the file thereby reducing I/O time and memory pressure:

convert -gravity southeast logo.png  -write MPR:logo    \
  \( -define jpeg:size=1280x720 before.jpg -resize ... \
  \( -define jpeg:size=1280x720 after.jpg  -resize ... 

这可以将我的机器上的时间减少大约25-30%.

That reduces the time by around 25-30% on my machine.

这是我的想法...

  • 首先设置gravity,因为它是设置,并且一直保持设置直到更改,
  • 加载徽标并保存到MPR,因为我们需要将其粘贴两次并且从磁盘读取两次很慢,
  • (...)内启动一些旁处理" 以加载before图片,调整其大小,粘贴徽标并保存到MPR以供以后使用,
  • 重复after图片的上一步,
  • 删除所有垃圾邮件,
  • 一种动画方式,
  • 为另一个动画,
  • 使动画永无止境,并将动画保存到GIF,
  • 删除第一帧以外的所有内容,调整其大小并另存为缩略图.
  • set the gravity first as it is a setting and remains set till changed,
  • load the logo and save to an MPR because we will need to paste it twice and reading from disk twice is slow,
  • start some "aside processing" inside (...) to load the before image, resize it, paste on the logo and save to MPR for later use,
  • repeat previous step for the after image,
  • delete all junk,
  • animate one way,
  • animate the other,
  • make animation endless, and save animation to GIF,
  • delete all except first frame, resize that and save as thumbnail.

关键字:动画,雨刮器效果,GIF动画

Keywords: animation, wiper effect, animated GIF

这篇关于消除ffmpeg和image-magic命令中的慢速因素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆