Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer night - @17.53
Activity rating: Four Stars Posts & Arts: 88/1k.beats ~ Boop! The forum will close in 983.beats! Random | Recent Posts | Guild Recents
News: :ha: :pc: Hello Melonland! :pc: :happy: Guild Events: There are no events!

+  MelonLand Forum
|-+  Projects & Art
| |-+  ⛽︎ ∙ Technology & Archiving
| | |-+  cool ffmpeg tricks


« previous next »
Pages: [1] Print Embed
Author Topic: cool ffmpeg tricks  (Read 216 times)
purpleraindrip
Newbie ⚓︎
*
View Profile WWW


meow meow meow
⛺︎ My Room

Guild Memberships:
Artifacts:
Joined 2026!
« on: a Summer night » Embed

I've recently found myself just converting files in command line using ffmpeg than having to open up adobe media encoder. It's just easier than opening up a whole ass app.

you can do it like this:
ffmpeg -i [input].[fileformat] [output].[fileformat]

of course it looks a lot different without the brackets. You also need to be in the right path

c:\users\person\downloads ffmpeg -i video.mov video2.mp4

like that. I also think it's really fun to compress video and audio cause the crunch is beautiful. so far I know how to mess with resolution, bitrate, and audio sample rate. it's like this

RESOLUTION
ffmpeg -i video.mp4 -vf scale=[width]:[height] video2.mp4

BITRATE
ffmpeg -i video.mp4 -b [desired data rate] video2.mp4
(you can also specify if you want to change the bitrate of the video or audio using -b:v or -b:a)
(also data rate is in thousands, example: 800k you gotta write it like that)

SAMPLE RATE
ffmpeg -i video.mp4 -ar [desired sample rate] video2.mp4
(while the bitrate will make the audio more compressed. for that real nice audio crunch you gotta bring down the sample rate. lowest is 8000 i think)

but yeah. those are all the ones that I know. But if anyone else knows any fun things to mess with using ffmpeg please reply! It's really fun making videos rly compressed and shitty and also it makes it easier to send shit to people on discord or apps with a file size limit. enjoy :D

Logged

:D :] ;P :L :I doot doot lalala~~~
Melooon
Hero Member ⚓︎
*****
View Profile WWWArt


So many stars!
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

Guild Memberships:
Artifacts:
You're a Star!Flinstone VitaminI got robbed by Dan Q on Melonland!Always working hard!Known Apple shillcoolest melon on the web!
« Reply #1 on: a Summer night » Embed

Here's a script I've not messed with in years but I made this video with it:

The idea was to have a folder with 100s of videos in it, the script them splits all those videos into individual frames, then recombine them into a single tiled montage of all the videos playing at once. I also got carried away and started using ImageMagick to rotate each frame a little each time, so you get the tiles spinning while the montage plays!

So you put your videos in the VIDEOS folder names 1.mp4 2.mp4 etc, it'll dump the frames into FRAMES, then process them!  :ozwomp:

Code
#!/bin/bash

# Warning videos must have number names like 1.mp4 or it wont work
VIDEOS=./videos/*
FRAMES=./frames
SORTEDFRAMES=./sortedframes
MONTAGES=./montages
FRAMECOUNT=2000				#how many frames to process must be less than limit
FRAMERATE=24					#force framerate on videos
PLAYBACKSPEED=10

mkdir -p $FRAMES
mkdir -p $SORTEDFRAMES
mkdir -p $MONTAGES

for path in $VIDEOS
do
  file=$(basename ${path})
  ffmpeg -i "$path" -r $FRAMERATE -vframes $FRAMECOUNT $FRAMES/$file-%04d.png
done

for (( f=0 ; f<=$FRAMECOUNT ; f++ ))
do
	padded_count=$(printf "%04d" $f)
	for file in $FRAMES/*-$padded_count.png
	do
		mkdir -p $SORTEDFRAMES/$padded_count
		mv "$file" $SORTEDFRAMES/$padded_count/$(basename ${$file})
	done
done

ROTATEDEG=0

for (( i=1 ; i<=$FRAMECOUNT ; i++ ))
do
	padded_count=$(printf "%04d" $i)
  	echo $padded_count
	  # 20x10 96px fits EXACTLY 200 on a 1080p screen at around 3cm at 27" - 10x20 is vertical
  	magick montage "$SORTEDFRAMES/$padded_count/*" -geometry 96x96\!+0+0 -tile 10x20 -rotate $ROTATEDEG -background black -bordercolor black -mattecolor black $MONTAGES/$i.jpg
	#magick montage "$SORTEDFRAMES/$padded_count/*" -geometry 96x96\!+0+0 -tile 10x20 -background black -bordercolor black -mattecolor black $MONTAGES/$i.jpg

	# image rotation
	ROTATEDEG=$(($ROTATEDEG+1))
	if [ $ROTATEDEG -ge $((361)) ]
	then
		ROTATEDEG=0
	fi
done

convert -delay $((100/$PLAYBACKSPEED)) $MONTAGES/*.png -quality 100 final.mp4

Logged


everything lost will be recovered, when you drift into the arms of the undiscovered

Artifact Swap: ShopkinRed TulipMellohiLurby?here comes the bap
Seechain
Casual Poster ⚓︎
*
View Profile WWW


⛺︎ My Room
Itch.io: My Games

Artifacts:
Joined 2026!
« Reply #2 on: a Summer night » Embed

ffmpeg is awesome. A while ago, I started converting reels to GIFs using this command.  :ok:

Code
ffmpeg -i reel.mp4 -vf "fps=12,scale=200:-1:flags=lanczos" reel.gif

https://i.imgur.com/eEFnAkH.gif

Logged

mrparker
Casual Poster ⚓︎
*
View Profile WWW

⛺︎ My Room

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Joined 2026!
« Reply #3 on: a Summer night » Embed

ffmpeg is awesome. A while ago, I started converting reels to GIFs using this command.  :ok:

Code
ffmpeg -i reel.mp4 -vf "fps=12,scale=200:-1:flags=lanczos" reel.gif

https://i.imgur.com/eEFnAkH.gif

I just want to say - the arguments on this command specifically can lower the FPS, scale the result down to a smaller size than the original (or, unintentionally upscale the output), and then apply lanczos resampling - depending on the source, this can all result in a larger size than the original in some instances! Use no options by default - or use scaling only, and add more as you see fit if performance (size, encoding/format) is your goal.

To prevent upscaling entirely, you can modify the above to be similar to this:

Code
ffmpeg -i reel.mp4 -vf "scale='min(200,iw)':-1" reel.gif

The parameters in the scale flag are specifically width:height. Read more in the official documentation here: https://trac.ffmpeg.org/wiki/Scaling

This specifically keeps the aspect ratio when resizing the width to 200px - which is why for the height parameter in this example we set it to -1 - which tells ffmpeg to keep the original value for the height from the original file.

The iw/ih variables in the min() function specifically applies to the initial height/width of the source - read it as
Code
[i]nitial [w]idth / [i]nitial [h]eight

This basically tells ffmpeg "Hey - only if the original is wider/taller than 200px, shrink it to 200px".

Like for width, the same can be done for the height parameter, too:

Code
ffmpeg -i reel.mp4 -vf "scale=-1:'min(200,ih)'" reel.gif

Instead of iw for width, for height we use ih instead.

Keep in mind as well, mp4 in a lot of cases is smaller for web applications, which is why a lot of the time "gifs" are actually mp4 files - you can loop mp4 videos in raw HTML, and even save more space by removing audio tracks - so that way the file is smaller and downloads faster (also add the attribute to mute the video just in case the user agent relies on that for autoplay).

If you still want to use an image format - apng, webp, avif all allow additional frames - sometimes compresses better and looks better than gif - resembling more of the original file! Try a mix and match of all - and keep whichever is smaller!

Of course, nothing wrong with doing what you want - just letting people know other options exist, just in case it matters at all. The gif format provides an aesthetic that it's known for - but the other file formats with the right parameters can replicate it, too - so even then you don't need to limit yourself to gif.

« Last Edit: a Summer night by mrparker » Logged
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #4 on: a Summer day » Embed

If anybody's looking for a better media encoder but isn't yet willing to teach themselves ffmpeg, can I swoop in and recommend Handbrake. It's free, open source, multiplatform, and basically backs onto ffmpeg under the hood.

I find it useful because I've got a handful of common output scenarios I use so I can have them saved as Handbrake presets and just drag files in. I use ffmpeg as well, but sometimes you just want a lazy GUI approach, y'know?

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif

Artifact Swap: PolyamorousI met Dan Q on Melonland!Joined 2025!
Seechain
Casual Poster ⚓︎
*
View Profile WWW


⛺︎ My Room
Itch.io: My Games

Artifacts:
Joined 2026!
« Reply #5 on: a Summer day » Embed

I just want to say - the arguments on this command specifically can lower the FPS, scale the result down to a smaller size than the original (or, unintentionally upscale the output), and then apply lanczos resampling - depending on the source, this can all result in a larger size than the original in some instances! Use no options by default - or use scaling only, and add more as you see fit if performance (size, encoding/format) is your goal.

To prevent upscaling entirely, you can modify the above to be similar to this:

Code
ffmpeg -i reel.mp4 -vf "scale='min(200,iw)':-1" reel.gif



I love this, it's like sorcery, and every spell has room for improvement. :wizard:




Logged

mrparker
Casual Poster ⚓︎
*
View Profile WWW

⛺︎ My Room

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Joined 2026!
« Reply #6 on: a Summer night » Embed

If anybody's looking for a better media encoder but isn't yet willing to teach themselves ffmpeg, can I swoop in and recommend Handbrake. It's free, open source, multiplatform, and basically backs onto ffmpeg under the hood.

I find it useful because I've got a handful of common output scenarios I use so I can have them saved as Handbrake presets and just drag files in. I use ffmpeg as well, but sometimes you just want a lazy GUI approach, y'know?


Oh yeah, this is also great if you have movies you want to re-encode for things like jellyfin (or plex - if you have money).

Logged
purpleraindrip
Newbie ⚓︎
*
View Profile WWW


meow meow meow
⛺︎ My Room

Guild Memberships:
Artifacts:
Joined 2026!
« Reply #7 on: a Summer night » Embed

Here's a script I've not messed with in years but I made this video with it:


this is on ffmpeg???? that's fucking crazy!!!!!!! i clearly do not know the full extent of what it can do. that is bananas

Logged

:D :] ;P :L :I doot doot lalala~~~
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Zap! Want to Login or Join ? Forum Art Hub Chat Webring Editor Recent Edits Tenement Arcade Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Frutiger Aero Forum Onio Club m15o's Web Services 32Bit Cafe iMood Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers
Minecraft: Online
Join: craft.melonking.net