0

I want to take a folder of mp4s and with ffmpeg compress them and turn them into gifs.

I do this for each file using this code:

ffmpeg -i input.mp4 -c:v libx264 -tune zerolatency -preset ultrafast -crf 40 -c:a aac -b:a 32k output.mp4

-crf can go to 63 and I can adjust how compressed the result file will be.

But how do I run that code for a whole folder of mp4s and get all of them compressed and turned into gifs?

So I am reading all possible problems on this board and have found making a .bat file with this code and then running it in command prompt:

for %F in (*.mp4) do (If not Exist "%~nF" MkDir "%~nF" ffmpeg -i %F -r 1 -qscale:v 2 %~nF\%~nF-%3d.jpg)

does close to what I need (except this is for breaking down multiple mp4s into jpgs).

This code changes multiple mp4s into gifs I have found:

for %i in (*.mp4) do ffmpeg -i "%i" "%~ni.mp3

As you can see I am trying to really toy with these codes, each one is excellent but I would love a combined ffmpeg code that A) takes a folder full of mp4s b) compresses them where I can customize the -crf and c) converts them to gifs with either a prefix or suffix added on or some other way where I can still recognize what the original file was.

If there is a way to do this without a customizable -crf then that is doable.

Thank you all for any help!

RayRay
  • 1
  • Why are you asking about gifs, but use output.mp4? Shouldn't it be output.gif? – Rotem Feb 21 '24 at 21:06
  • your right but that iknow how to change. – RayRay Feb 22 '24 at 05:11
  • The issue is that GIF file doesn't support H.264 codec, so we can't use -c:v libx264 (and also not -c:a aac). -crf 40 is not relevant for GIF files. Your question doesn't make sense to me. It is also unclear if you want to create "Animated GIF" files. – Rotem Feb 22 '24 at 06:02
  • Rotem thank you for that reply, I am very noobie when it comes to the actual coding so I appreciate you letting me know that code won't apply to gifs. Yes to clarify I DO want to create animated Gifs. Is there any way to with one code compress mp4s or webms and then convert to gifs, or from what you are telling me possibly converting those files into gifs and then batch compress all the gifs? I am just throwing out the codes that I do use now, but I am open to batch converting then compressing into gifs. Thanks! – RayRay Feb 22 '24 at 18:13
  • Here is an example for converting an MP4 to Animated GIF. I suggest you to read the Wikipedia page for better understanding the limitations of Animated GIF. The palette subject may be important. It is also important understanding that Animated GIF is not a video format, but a sequence of images with low compression ratio (GIF files may become very large compared to MP4). Start by converting one MP4 file and see if it meets your expectations. – Rotem Feb 22 '24 at 23:03

0 Answers0