dimodiyer

Create a Minecraft 1.21.4 Fabric mod that allows players to record gameplay smoothly with minimal lag, supporting selectable resolutions (4K, 1440p, 1080p) at a fixed 60 FPS using optimized framebuffer capture and async/background encoding to reduce impact on the render thread; include controls via a keybind and optional on-screen toggle with a REC indicator and timer; recordings should automatically export to a configurable folder (default .minecraft/recordings/); integrate FFmpeg with an in-game option to detect, download, and auto-configure it so users don’t need external setup, and provide performance options like bitrate adjustment to ensure smooth recording even on lower-end systems.

Kodari AI
KodariApr 18 at 12:55 pm 38,043 (v2)

I’ll start by reading the necessary docs to ensure correct 1.21.4 patterns.

PixelRecorder
A Fabric 1.21.4 client-side mod for in-game gameplay recording with minimal performance impact. Captures the framebuffer using OpenGL and pipes raw frames to FFmpeg via async background encoding. Supports selectable output resolutions (4K, 1440p, 1080p) at 60 FPS with configurable bitrate. Features a keybind-toggled HUD overlay showing a blinking REC indicator and timer, a settings screen, auto FFmpeg detection and one-click download for Windows, and automatic export to .minecraft/recordings/.
  • Pure client-side mod — keybind toggles recording, HUD overlay shows REC + timer, settings screen controls resolution/bitrate/output folder/FFmpeg

  • glReadPixels on render thread at ≤60fps → byte[] into LinkedBlockingQueue → background writer thread streams raw frames to FFmpeg stdin for async encoding

  • FFmpeg auto-detection on PATH and in game dir, one-click download for Windows (BtbN static zip), platform instructions for Linux/macOS

Now I have everything needed. Writing all files:


PixelRecorder
A Fabric 1.21.4 client-side mod for in-game gameplay recording with minimal performance impact. Captures the framebuffer using OpenGL and pipes raw frames to FFmpeg via async background encoding. Supports selectable output resolutions (4K, 1440p, 1080p, 720p) at 60 FPS with configurable bitrate. Features a keybind-toggled HUD overlay showing a blinking REC indicator and elapsed timer, a full settings screen, auto FFmpeg detection and one-click download for Windows, and automatic export to .minecraft/recordings/.

The mod is fully scaffolded with these key design decisions:

  • Frame capture (MinecraftClientMixin → render(Z)V TAIL): glReadPixels on the GL/main thread at ≤60 fps using a nanosecond rate limiter, copying pixels to byte[] and offering to a LinkedBlockingQueue<byte[]>(30) — frames are dropped silently if the encoder falls behind rather than stalling the render thread

  • Async encoding (RecordingManager): a dedicated PixelRecorder-Writer thread drains the queue and streams raw rgb24 bytes into FFmpeg’s stdin; a second thread drains FFmpeg’s stderr to prevent pipe stalls; a third PixelRecorder-Stopper thread joins both after stopRecording() so the game never freezes

  • FFmpeg command includes -vf vflip,scale=WxH to correct OpenGL’s upside-down origin and rescale to the target resolution, -preset veryfast -b:v Xk -pix_fmt yuv420p -movflags +faststart for compatible MP4 output

  • FFmpeg detection checks config path → local recordings/ffmpeg/ dir → system PATH; Windows users get a one-click download that fetches the BtbN static zip and extracts ffmpeg.exe; Linux/macOS users see platform-specific install instructions

  • Settings screen (F10): cycles resolution, adjusts bitrate in 1000 kbps steps (1000–80000), toggles HUD visibility, shows output path and FFmpeg status with color coding

  • HUD (top-right): blinking ● REC MM:SS in red while recording; post-recording status messages auto-clear after 4 seconds

Kodari can make mistakes. Review important code before using.
Files
gradle
src
build.gradle
gradle.properties
settings.gradle
Code
17 978
src/client/java/com/pixelrecorder/PixelRecorderClient.java
package com.pixelrecorder;

import com.pixelrecorder.config.ConfigManager;
import com.pixelrecorder.hud.RecordingHud;
import com.pixelrecorder.recording.RecordingManager;
import com.pixelrecorder.screen.RecordingSettingsScreen;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;

public class PixelRecorderClient implements ClientModInitializer {

    public static KeyBinding toggleRecordingKey;
    public static KeyBinding openSettingsKey;

    @Override
    public void onInitializeClient() {
        ConfigManager.load();

        toggleRecordingKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.pixelrecorder.toggle",
                InputUtil.Type.KEYSYM,
                GLFW.GLFW_KEY_F9,
                "category.pixelrecorder"
        ));

        openSettingsKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.pixelrecorder.settings",
                InputUtil.Type.KEYSYM,
                GLFW.GLFW_KEY_F10,
                "category.pixelrecorder"
        ));

        HudRenderCallback.EVENT.register(RecordingHud::render);

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (toggleRecordingKey.wasPressed()) {
                RecordingManager rm = RecordingManager.INSTANCE;
                if (rm.isRecording()) {
                    rm.stopRecording();
                } else {
                    rm.startRecording();
                }
            }

            while (openSettingsKey.wasPressed()) {
                if (client.currentScreen == null || !(client.currentScreen instanceof RecordingSettingsScreen)) {
                    client.setScreen(new RecordingSettingsScreen(client.currentScreen));
                }
            }
        });
    }
}