Stacking two image series

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
TWagner
Posts: 1
Joined: 2019-05-27T01:35:19-07:00
Authentication code: 1152

Stacking two image series

Post by TWagner » 2019-05-27T02:03:31-07:00

Hello,

yet I have not been able to find out how to do the following:

I have two image series - V01-0000.png to V01-0100.png and V02-0000 to V02-0100.png - where I try to stack horizontally V01-0000.png with V02-0000.png, V01-0001.png with V02-0001.png and so on. Once all stacked images are created I would use ffmpeg to create an animation.

I know how to use +append to stack two single images, but how to use this on two image series? Scripts like this one don't produce what I am trying to achieve (at least I have not been able to make it work):

convert.exe "V01-%%04d.png" +append "V02-%%04d.png" "Stack-%%04d.png"

This command produces a single image with all images from the series stacked.

My current work around: Use ffmpeg to create separate animations for each image series and then stack the animations using ffmpeg again.

Any advice regards where my thinking is wrong is very much appreciated.

Thanks in advance,
Thomas

My system:
Windows 7, Imagemagick 7.0.8-27 Q16 x64 2019-02-09

snibgo
Posts: 12299
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Stacking two image series

Post by snibgo » 2019-05-27T03:39:10-07:00

I would do it in a shell loop, like this. Windows BAT syntax:

Code: Select all

for /L %%I in (0,1,100) do (
  set LZ=000%%I
  set LZ=!LZ:~-4!
  magick V01-!LZ!.png V02-!LZ!.png +append stack-!LZ!.png
)
LZ is the number with 4 digits, including leading zeros.

If all the images fit in memory, it can be done in a single "magick" command, but it is awkward.
snibgo's IM pages: im.snibgo.com

User avatar
GeeMack
Posts: 723
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Stacking two image series

Post by GeeMack » 2019-05-27T08:50:20-07:00

TWagner wrote:
2019-05-27T02:03:31-07:00
My current work around: Use ffmpeg to create separate animations for each image series and then stack the animations using ffmpeg again.

Any advice regards where my thinking is wrong is very much appreciated.
EDITED TO ADD:
Apparently I misunderstood the question, so I edited out my previous answer to avoid confusion.

There are a few ways to "+append" the images from one list onto the corresponding images from another list. Assuming all the images in both lists are the same dimensions, a command like this might get you pointed in the right direction...

Code: Select all

convert "V01-*.png" -virtual-pixel none ^
   -set option:distort:viewport %[fx:w*2]x%[h] -distort SRT 0 ^
   null: "V02-*.png" -gravity east -layers composite output%04d.png
That reads in the first list and extends the width of each image to twice its dimension toward the right.

Then it adds the IM special file "null:" as a separator before it reads in the second list.

The gravity is set to "east" so images from the second list get composited over the extended regions on the right sides of the first list with "-layers composite". That takes both lists separated by that "null:" and effectively appends each image from the second list to the right of each corresponding image from the first list.

The output files will be "output0000.png" "output0001.png" ... "outputNNNN.png".

If you're going to take those appended images straight to ffmpeg, you should be able to do that without writing them to disk. Modify my above example a bit like this...

Code: Select all

convert "V01-*.png" -virtual-pixel none ^
   -set option:distort:viewport %[fx:w*2]x%[h] -distort SRT 0 ^
   null: "V02-*.png" -gravity east -layers composite PNG:- | ffmpeg -i - finished.mpg
That assures the output images are PNG format, pipes them to the input "-i -" of ffmpeg, and that program takes over to create the video.

If you're using this in a Windows BAT script you need to double all the percent signs "%%".

Post Reply