cri.dev 🤦‍♂️ about ✍️ posts 🗞️ rss

No ImageMagick? No problem, use FFmpeg!

Published on

Ok this is clickbait, but hear me out.

The alternative to imagemagick for simple scaling, rotation and image conversion actually works.

And I’ll explain why I didn’t/couldn’t go with ImageMagick (on my Kindle), which would be my go-to tool.

–

I rooted my Kindle.

The shell is very limited.

The Kindle runs on

Linux kindle 3.0.35-lab126 #8 PREEMPT Fri Sep 13 12:49:59 UTC 2024 armv7l GNU/Linux

I don’t have a package manager, I could install Alpine on it and get apk but couldn’t get it to work after enough fiddling, and I actually didn’t need it turns out.

I wanted to display an image from my Tapo camera, but it doesn’t have a snapshot endpoint, only an RTSP stream.

So here comes FFmpeg to the rescue.

Here is the command I needed to get the image from the stream, and more importantly resize it, convert to gray-scale 8-bit PNG and rotate it:

ffmpeg -i "rtsp://<username>:<password>@<ip>:554/stream1"
-f image2 # stores sequence of individual image frames as separate files
-pix_fmt gray # convert to grayscale, 8bit PNG
-vf "scale=1920:-1,transpose=1" # scale it, maintain aspect ratio, and rotate by 90degrees clockwise
-vframes 1 # I just need 1 frame
output.png

I hear you shouting at the screen “BUT I DON’T HAVE A STREAM, I JUST HAVE AN IMAGE!”

Simply replace the stream url with your local image.

Here is a link to the FFmpeg docs about its filters

Here, have a slice of pizza 🍕