Skip to content

Instantly share code, notes, and snippets.

@guillaC
Last active April 22, 2024 19:43
Show Gist options
  • Save guillaC/41dd2d69444c4579d19c5529b75c8191 to your computer and use it in GitHub Desktop.
Save guillaC/41dd2d69444c4579d19c5529b75c8191 to your computer and use it in GitHub Desktop.
Raylib Vidéo Creator with ffmpeg
using Raylib_cs;
using System.Diagnostics;
namespace AsciiI
{
public static class VideoCreator
{
public static List<Image> Images = new();
static readonly string FfmpegPath = @"Ressources/ffmpeg.exe";
public static void RecordAnimation(Texture2D texture)
{
Image frameImage = Raylib.LoadImageFromTexture(texture);
Images.Add(frameImage);
}
public static void CreateVideoFromFrames(string outputVideoPath, int fps = 30)
{
// Exporter chaque texture dans un fichier PNG
for (int i = 0; i < Images.Count; i++)
{
Image frameImage = Images[i];
string framePath = $"frame_{i}.png";
Raylib.ImageFlipVertical(ref frameImage);
Raylib.ExportImage(frameImage, framePath);
Raylib.UnloadImage(frameImage);
}
// Exécutez la commande FFmpeg pour créer la vidéo à partir des Images exportées
ProcessStartInfo processInfo = new ProcessStartInfo(FfmpegPath, $"-r {fps} -i frame_%d.png -c:v libx264 -preset veryslow -crf 16 -pix_fmt yuv420p {outputVideoPath}");
processInfo.UseShellExecute = false;
Process process = Process.Start(processInfo);
process.WaitForExit();
Images.Clear();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment