• he/they

It's a horrible day on the Internet, and you are a lovely geuse.

Adult - Plants-liking queer menace - Front-desk worker of a plural system - Unapologetic low-effort poster

✨ Cohost's #1 Sunkern Fan(tm) ✨

[Extended About]

--
Three pixel stamps: a breaking chain icon in trans colors against a red background, an image of someone being booted out reading "This user is UNWELCOME at the university", and a darkened lamppost.(fallen london stamps by @vagorsol)



bazelgeuse-apologist
@bazelgeuse-apologist

the really sadistic thing about like, making gifs from videos is that you don't need to rely on weird and maybe shady sites with a lot of limitations! there is a tool that can trim videos, crop videos, and convert them to gifs, and like five dozen other things besides! and it's COMPLETELY FREE AND LEGIT!!!

...the catch is, it's operated entirely through the command line.

yes, this is about ffmpeg.

edit: LINKS


bazelgeuse-apologist
@bazelgeuse-apologist

ffmpeg be like: how would you like to learn a programming language and also the nuances of image encoding and color theory in order to rotate a png ninety degrees


bazelgeuse-apologist
@bazelgeuse-apologist
----- `
ffmpeg -i input.mkv -filter_complex "fps=15,scale=400:-1:flags=lanczos,split[s0][s1];[s0] palettegen=stats_mode=diff [p];[s1][p] paletteuse" output.gif
` -----

this is my "turn this video into a gif" ffmpeg command I stole from stack overflow and then frankensteined. ignore the lines before and after, they're there for ease of reading + copying.

change input.mkv to whatever your video is. this outputs a 15 fps gif that's 400px wide by default but you can change that by editing the fps and scale things. the rest, I have no fucking idea. something about sampling method and smushing together the disparate steps of gif creation into one command or something. hopefully it won't explode your computer

you can download ffmpeg here. like, if for some reason you want to. god have mercy on your soul

edit: as for cropping and trimming videos, @OniLink recommended this tool called HandBrake. you can do that in ffmpeg too, but like, why

edit 2: @obspogon shared some tools to make ffmpeg a slightly less hateful experience


You must log in to comment.

in reply to @bazelgeuse-apologist's post:

I love ffmpeg!

Not even ironically, I just really like it.

That being said for GIFs specifically I think I've got a chunk of magic text because gif color spaces are fucked. Also sites really shouldn't still be using GIF now, videos use a hell of a lot less bandwidth for the same data.

(Cohost will get it later on I'm sure, I'm not worried about it here as you can just link an external video)

in reply to @bazelgeuse-apologist's post:

This actually made me go look up palettegen and see what it's doing.

This is probably a bad idea because while I do love it, I wouldn't call myself a ffmpeg expert, but I want to try and dEmYsTiFy this a bit. But.... I'm going to explain everything this command is doing. Again, I really like fffmpeg. I'm sorry.

Normally when you use ffmpeg for most normal video conversion stuff, you just tell it which codec to use for audio and video (-c:a, -c:v) along with whatever flags you want to give each of those codecs. Say, the target bitrates. For some formats, ffmpeg will just try and throw frames into the desired format; ffmpeg -i video.mp4 frame%03d.png will just spew out every frame into individual pngs, as an example.

So just getting ffmpeg to spit out an animated gif from a video is easy, you just tell it to... output a gif. ffmpeg -i video.mp4 video.gif. The problem is the gif format itself kind of sucks, it's not efficient and has color limitations and such, so this will spit out a HUGE file. Filter_complex is basically just a way to chain a bunch of filters together, and here it's being used primarily to... generate and use a color palette.

Here's each step of that chain.

fps=15 - Set the frame rate, because full 60fps makes GIF files huge.
scale=400:-1 - Downscale the image to 400 width, and adjust the height to maintain aspect ratio. You can use -2 here instead of -1 to make it round to the nearest integer number, in case it errors because of a weird resolution scale.
flags=lanczos - The scaling algorithm. I usually don't use this myself.
split[s0][s1] - This splits the current datastream into two: s0 and s1. This is the key part of filter_complex, you can basically set audio or video streams into variables and create... well, complex chains of filters.
[s0]palettegen=stats_mode=diff[p] - Directly from the docs: "Generate one palette for a whole video stream." I'm 99% sure this is just picking colors out from the video stream, again because GIFs stink and we gotta do all this work to make them look good.
[s1][p]paletteuse - This takes the scaled video feed from s1 and the palette we just made p and downsamples the color space in the video to match the palette. In this case it's 256 colors, so there's a lot of math happening from palettegen to make things look good.

And from here, the chain spits out the video data which ffmpeg then goes "I need to toss this into a gif container" and does so.

And that's it! I hope this is in some way helpful and not annoying.