Skip to content

Conversation

tsuko
Copy link

@tsuko tsuko commented Aug 27, 2017

I extended Moments for my own project, and I thought other people might find these changes useful, as I get more stable colours and substantially faster encoding time now.

What Moments does now:
The existing version of Moments creates a new colour palette for every frame in a gif. NeuQuant is computationally expensive, so this makes encoding slow and, more importantly, it can result in "flickering" colours every frame when the NeuQuant operation quantises the colors slightly differently with a moving camera or changing colors on the screen.

What my additions do:
My fork gives Moments the ability to sample several frames from a gif, analyze those frames together with NeuQuant, and create a single color palette that every frame will map to, without further NeuQuant calls.

I've added a "Frames Per Color Sample" field to the inspector, which allows you to sample every n-th frame in a recording for color mapping purposes. If the "Frames Per Color Sample" is set to zero, Moments reverts to its current default behaviour of creating a brand new color palette every frame.

The results:
By setting "Frames Per Color Sample" to 6, for instance, I halved the encoding time for my 5.5 second gifs on Windows and I get rock-solid colours for the duration of my gif, without the frame-by-frame flickering I experienced previously.

BEFORE: (please note the flickering pinks and purples on some objects)
ultimateultimate-201708271640302424

AFTER:
ultimateultimate-201708271643329345

Paul Kopetko added 2 commits August 27, 2017 17:33
…l adhere to by analyzing a sample of frames (set as every n-th frame in the Inspector) and producing a NeoQuant palette out of those combined frames.
@Chman
Copy link
Owner

Chman commented Dec 11, 2017

Whoa not sure how I missed this PR. That's a very nice addition, thanks for taking the time to implement it. I think the PR is missing a file though? See the inline comment.

m_Width = serializedObject.FindProperty("m_Width");
m_Height = serializedObject.FindProperty("m_Height");
m_FramePerSecond = serializedObject.FindProperty("m_FramePerSecond");
m_FramesPerColorSample = serializedObject.FindProperty("m_FramesPerColorSample");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recorder doesn't have a serialized m_FramesPerColorSample field. Did you miss a file in your commit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're quite right! I hadn't copied my changes to Recorder.cs across. It should be good to go now. Thanks, @Chman.

roguesleipnir added a commit to roguesleipnir/Unity-Moments that referenced this pull request Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants