FFmpegLib is a technical library mod for Minecraft NeoForge 1.21.1 that integrates FFmpeg multimedia capabilities directly into the game. It adds no content for players, serving strictly as an API for other mods to handle dynamic media processing in background threads without lagging the main game loop
Please report any errors and/or ask any questions in the comments and/or via private message to me
Features :
— Executable Management: Automatically tracks and manages the ffmpeg.exe file inside config/ffmpeglib/
— Asynchronous Orchestrator: Provides a Java API (FFmpegOrchestrator) to run heavy video/audio processing tasks using CompletableFuture
— Frame Extraction: Converts video files (e.g., mp4) into a sequence of PNG frames at a specified FPS for custom GUI or in-game rendering
— Crash Isolation: Runs all decoding tasks in separate processes to prevent Minecraft from crashing if a media file is corrupted.
API Methods
Video Frame Extraction
Converts a video into sequential images named frame_%04d.png inside the target folder
— Signature
public static CompletableFuture<Void> extractFrames(File ffmpegExe, File videoFile, File targetDir, int fps)
— Parameters
ffmpegExe: The path to the verified FFmpeg executable
videoFile: The source video file to process
targetDir: The destination folder for the output PNG frames
fps: The target frame rate (number of frames extracted per second)
An example from lost in fog (approximate)
@SubscribeEvent
public static void onClientLogin(net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent.LoggingIn event) {
if (!ffmpegExe.exists() || !ffmpegExe.isFile()) {
Minecraft.getInstance().execute(() -> {
Minecraft.getInstance().setScreen(new FfmpegMissingScreen(null));
});
return;
}
CompletableFuture.runAsync(() -> {
try {
for (int d = 1; d <= 5; d++) {
File targetDir = new File(cadriDir, "video" + d);
File videoFile = new File(videoDir, "anal" + d + ".mp4");
if (!videoFile.exists()) extractVideoResource(d, videoFile);
if (!targetDir.exists()) targetDir.mkdirs();
File[] existingFrames = targetDir.listFiles();
if (existingFrames == null || existingFrames.length == 0) {
// HERE
FFmpegOrchestrator.extractFrames(ffmpegExe, videoFile, targetDir, 25).join();
}
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
I'm not an expert in programming or creating libraries for mods, so this library turned out to be small. I tried to describe all the methods used, and this mod is mostly intended as a supplement to lost in fog rather than a standalone library