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.)
e.g. https://media.evercam.io/v1/cameras/1lowe-scnoe/compares/lower-jreyh.gif
All the commands are written below, doing these operations
- Resize before after image.
- create a Gif using both images.
- Add a log to Gif.
- Create an MP4 file of from GIF.
- Create a thumbnail from mp4 file.
the logo is:
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.
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
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
then to create a thumbnail from this mp4.
ffmpeg -i compa-efxfphu.mp4 -vframes 1 -vf scale=640:-1 -y thumb-compa-efxfphu.jpg
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?
Or do you see any chance to reduce these all 4 in one? any input will be so thankful.
Updated Answer
Here is my best shot at this, it runs in about 50% of the time of the original answer...
Here's my thinking...
gravity
and initialiselibjpeg
's "shrink-on-load" feature,(...)
to load thebefore
image, resize it, paste on the logo and save to MPR for later use,after
image,Original Answer
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:You can probably also create the thumbnail with that command too, if you change the last line from:
to
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:
That reduces the time by around 25-30% on my machine.
Here's my thinking...
gravity
first as it is a setting and remains set till changed,(...)
to load thebefore
image, resize it, paste on the logo and save to MPR for later use,after
image,Keywords: animation, wiper effect, animated GIF