DEV Community

Quantooox
Quantooox

Posted on

From a database to a YouTube Short with Pillow and ffmpeg (no video editor)

Every night our server writes a plain-language post about the day's data and turns it into a short vertical video for YouTube Shorts, Instagram Reels and Facebook. No video editor, no paid API: Pillow draws the slides and ffmpeg joins them.

1. Draw slides with Pillow

from PIL import Image, ImageDraw, ImageFont
img = Image.new("RGB", (1080, 1920), "#0f172a")          # 9:16 vertical
d = ImageDraw.Draw(img)
font = ImageFont.truetype("DejaVuSans-Bold.ttf", 92)
d.text((80, 300), "Biggest score moves", font=font, fill="#ffffff")
img.save("slides/0.png")
Enter fullscreen mode Exit fullscreen mode

A small helper wraps text to a width so long sentences don't run off the slide.

2. Join them with ffmpeg's concat demuxer

file 'slides/0.png'
duration 5
file 'slides/1.png'
duration 5
file 'slides/1.png'
Enter fullscreen mode Exit fullscreen mode

(The last file is repeated, or ffmpeg ignores its duration.)

ffmpeg -y -f concat -safe 0 -i list.txt -f lavfi -i anullsrc=r=44100:cl=stereo \
  -shortest -r 30 -pix_fmt yuv420p -c:v libx264 -c:a aac video.mp4
Enter fullscreen mode Exit fullscreen mode

The anullsrc input adds a silent audio track. Some platforms reject videos with no audio stream at all.

3. Check every caption before it's posted

Every caption goes through a compliance check (a regex of words we never use, plus a required disclaimer) before anything is uploaded. If a post fails, it's skipped and logged, and the rest still go out.

Cost

Zero: an Always Free cloud VM, open-source tools, and a self-hosted scheduler (Postiz) to post to each platform.


From Quantooo Lab, the makers of quantooo.com, a free, open and educational quant lab: every formula, every test and every failure is public. See it here: https://quantooo.com/learn?tag=daily

Educational, not investment advice.

Top comments (0)