Using ffmpeg to combine videos side by side
note, November 04, 2023 on Mitja Felicijan's blog
I had a 4 webm videos (each 492x451) that I wanted to combine to be played side
by side and I tried iMovie and
Kdenlive and failed to do it in an easy way. I needed
this for Github readme file so it also needed to be a GIF.
The following is the ffmpeg version of it.
ffmpeg -y \
-i 01.webm \
-i 02.webm \
-i 03.webm \
-i 04.webm \
-filter_complex "\
[0:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a0]; \
[1:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a1]; \
[2:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a2]; \
[3:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a3]; \
[a0][a1][a2][a3] xstack=inputs=4:layout=0_0|w0_0|w0+w1_0|w0+w1+w2_0, scale=1000:-1 [v]" \
-map "[v]" \
-crf 23 \
-preset veryfast \
trigraphs.gif
- This will produce
trigraphs.gif
that is also scaled to max 1000px in width
(refer to scale=1000:-1
).
- The important part for 4x1 stack is
xstack=inputs=4:layout=0_0|w0_0|w0+w1_0|w0+w1+w2_0
.
- This will also cap frame rate to 6 (refer to
fps=6
) since that is enough and
this makes playback of GIFs smoother in a browser.

-
In its original form, a peephole optimization applied to a collection of instructions located close together in a program. For example, in a register transfer language we might find this sequence of instructions: r0 = xor r8, -1 r1 = xor r9, -1 r0 = and r0, r1 Here, assuming the two’s complement representation, -1 […]
-
So I got my Raspberry PI 5. And like in my previous post, I compiled LLVM 17 on the Raspberry PI 5, and have compared the compile speed versus the Raspberry PI 4. I’m going to do the same steps: Compile LLVM using the default clang got via apt-get. Compile LLVM again using the clang we just built. And compile it a thir...
-
Richard Stallman, the founder of the Free Software Foundation, has been subject to numerous allegations of misconduct. He stepped down in 2019, and following his re-instatement in 2021, a famous open letter was published in which numerous organizations and individuals from throughout the Free Software ecosystem called ...
-
tags: plan9, random, zig Nothing profound here. But sometimes the internet collective can still be surprising. Apparently, you can already cross-compile Zig (at least the basic stuff) for plan9. Now this is fun! Also, a note to self more than anything: while zig itself is simple and quick to take in, the built-in build...
-
Getting "url" parameter is valid but upstream response is invalid error with Next/Image on WSL2
-
After spending countless hours trying to understand how to deploy my apps on Kubernetes for the first time to host Mirage, an AI API service that I run, I ended up making myself a promise that the next app I work on would be using a more productive & simpler
-
Accounting is fundamental to starting a business. You need to have a basic understanding of accounting principles and essential bookkeeping. I had to learn it. There was no choice. For filing taxes, your CPA is going to ask you for an Income Statement (also known as P/L statement). If
-
For over 10 years now, I run two self-built NAS (Network Storage) devices which serve media (currently via Jellyfin) and run daily backups of all my PCs and servers. In this article, I describe my goals, which hardware I picked for my new build (and why) and how I set it up. Design Goals I use my network storage device...
-
It's not news that a great deal of email in the world today is written in HTML, and has been for some time. If you insist on plain text email, you're increasingly an anachronism. Many people writing email probably don't even think about people who prefer plain text, and I think many mail clients will default to HTML ev...
-
This article documents my learnings from designing and building a DIY Pen Plotter during the summer of 2023. My ultimate goal is to build my…