问题
There are two images: a.jpg and b.jpg.
I just want to know how to join them into one image using ffmpeg
.
How should I finish the ffmpeg -i a.jpg -i b.jpg
command to get a c.jpg output image?
This is an example of what I am trying to achieve:
a.jpg
b.jpg
c.jpg
回答1:
I think that tile is your ffmpeg
command.
You can find more info on Superuser.
Try:
ffmpeg -i a.jpg -i b.jpg -filter_complex scale=120:-1,tile=2x1 output.jpg
回答2:
Use the hstack filter:
ffmpeg -i a.jpg -i b.jpg -filter_complex hstack output
If you want to vertically stack use vstack
instead.
回答3:
Watch out! Dirty hacks ahead!
Pay attention to the LordNeckbeard's answer since it is much better than the hacks of mine.
Álvaro's answer didn't work for me so I did more research to solve the issue. This is what I've learnt:
I am going to use the following variables.
A_HEIGHT=458
A_WIDTH=370
B_HEIGHT=600
B_WIDTH=750
B_CROP_X=112
B_CROP_Y=0
A_IMAGE=a.jpg
B_IMAGE=b.jpg
B_IMAGE_SCALED=b-scaled.png
B_IMAGE_CROPPED=b-cropped.png
C_IMAGE_WITHOUT_A=c-without-a.png
C_IMAGE=c.png
Scale and crop
In case your images are not of the same width and height.
This script scales B to be of the size as A.
# Scale.
ffmpeg -y -i ${B_IMAGE} -vf \
scale=${A_HEIGHT}*${B_WIDTH}/${B_HEIGHT}:${A_HEIGHT} ${B_IMAGE_SCALED}
# Crop.
ffmpeg -y -i ${B_IMAGE_SCALED} -vf \
"crop=${A_WIDTH}:${A_HEIGHT}:${B_CROP_X}:${B_CROP_Y}" ${B_IMAGE_CROPPED}
Merge / join two images
ffmpeg -y -i ${B_IMAGE_CROPPED} -filter_complex tile=2x1 ${C_IMAGE_WITHOUT_A}
Now the C_IMAGE_WITHOUT_A
lacks A; there is a black background instead. (You'll should get something similar to the picture below.)
I have found a way to join those two images nevertheless:
ffmpeg -y -i ${C_IMAGE_WITHOUT_A} -i ${A_IMAGE} \
-filter_complex overlay=${A_WIDTH}:0 ${C_IMAGE}
来源:https://stackoverflow.com/questions/24604689/how-to-join-two-images-into-one-with-ffmpeg