84 lines
1.8 KiB
C
84 lines
1.8 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
#include "raylib.h"
|
|
#include "rlgl.h"
|
|
|
|
void draw_frame(int frame)
|
|
{
|
|
BeginDrawing();
|
|
{
|
|
ClearBackground(BEIGE);
|
|
DrawText(TextFormat("frame: %d", frame), 0, 0, 50, RED);
|
|
DrawRectangle(frame*3, frame*2, 50, 50, BLUE);
|
|
}
|
|
EndDrawing();
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int pipefd[2];
|
|
pid_t pid;
|
|
|
|
if (pipe(pipefd) == -1) {
|
|
printf("ERR: pipe\n");
|
|
return -1;
|
|
}
|
|
|
|
pid = fork();
|
|
if (pid == -1) {
|
|
printf("ERR: fork\n");
|
|
return -1;
|
|
}
|
|
|
|
if (pid == 0) {
|
|
close(pipefd[1]);
|
|
|
|
dup2(pipefd[0], STDIN_FILENO);
|
|
close(pipefd[0]);
|
|
|
|
execlp("ffmpeg", "ffmpeg",
|
|
"-y",
|
|
"-f", "rawvideo",
|
|
"-pix_fmt", "rgba",
|
|
"-s", "900x600",
|
|
"-r", "60",
|
|
"-i", "-",
|
|
"output.mp4",
|
|
NULL);
|
|
|
|
// unreachable if ffmpeg launch
|
|
printf("ERR: execlp");
|
|
return -1;
|
|
} else {
|
|
close(pipefd[0]);
|
|
|
|
InitWindow(900, 600, "screen record test");
|
|
// NOTE: lower FPS if frame bug
|
|
SetTargetFPS(60);
|
|
Vector2 scale = GetWindowScaleDPI();
|
|
int width = GetScreenWidth();
|
|
int height = GetScreenHeight();
|
|
|
|
int frame;
|
|
for (frame = 0; frame < 300; frame++) {
|
|
draw_frame(frame);
|
|
|
|
int w = width*scale.x;
|
|
int h = height*scale.y;
|
|
|
|
unsigned char *screen_data = rlReadScreenPixels(w, h);
|
|
write(pipefd[1], screen_data, w*h*4*sizeof(*screen_data));
|
|
|
|
RL_FREE(screen_data);
|
|
}
|
|
|
|
close(pipefd[1]);
|
|
wait(NULL);
|
|
|
|
printf("%d frame in %.02fs\n", frame, GetTime());
|
|
}
|
|
}
|