ffmpeg

ffmpeg hstack long list of files


I have 1920 images that are 1920x1080 in resolution. I've sliced each image into 1x1080 slices. They are in folders labeled img0001_slices, img0002_slices, ... img1920_slices. In the folders the slices are labeled img0001_slice_0, img0001_slice_1, ... img0001_slice_1919. I want to use ffmpeg to form new images out of the slices. New image one should be the first slice of all the original images lined up horizontally from img1920 on the left to img0001 on the right. New image two should be the second slice of the original images in the same order, new image three should be the third, so on.

So far I've been trying to get a shell script to work where I first create a text file of all the different slices to be combined, i.e.

slice_0_inputs.txt

file 'img1920_slices/img1920_slice_0.png'
file 'img1919_slices/img1919_slice_0.png'
file 'img1918_slices/img1918_slice_0.png'
.
.
.
file 'img0001_slices/img0001_slice_0.png'

Then I run ffmpeg -f concat -i slice_0_inputs.txt -filter_complex "hstack=inputs=1920" reconstructed_slice_0.png

But I keep getting the error

Cannot find a matching stream for unlabeled input pad hstack
Error binding filtergraph inputs/outputs: Invalid argument

I've tried reducing the file slice_0_inputs.txt to just 2 filepaths and running ffmpeg -f concat -i slice_0_inputs.txt -filter_complex "[0:v][1:v]hstack=inputs=2" test.png

But I get the error

Invalid file index 1 in filtergraph description [0:v][1:v]hstack=inputs=2.
Error binding filtergraph inputs/outputs: Invalid argument

Could someone please help me understand the issue I am running into here?


Solution

  • An input fed from the concat demuxer is a single input consisting of the concatenated frames in series. hstack expects parallel inputs so multiple -i declarations. However, that would be very inefficient in this case.

    You can continue to use the concat method but with the tile filter.

    ffmpeg -f concat -i slice_0_inputs.txt -filter:v "tile=layout=1920x1" reconstructed_slice_0.png


    You don't need to save the column slices as separate files. You can create a concat list of full-size images, and then run in series,

    ffmpeg -f concat -i full_inputs.txt -filter:v "crop=1:ih:X:0:exact=1,tile=layout=1920x1" reconstructed_slice_X.png

    where X iterates from 0 to 1979.