aboutsummaryrefslogtreecommitdiffstats
path: root/src/ffmpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ffmpeg.c')
-rw-r--r--src/ffmpeg.c58
1 files changed, 44 insertions, 14 deletions
diff --git a/src/ffmpeg.c b/src/ffmpeg.c
index 37d5185..21692d0 100644
--- a/src/ffmpeg.c
+++ b/src/ffmpeg.c
@@ -7,13 +7,15 @@
#include "ffmpeg.h"
-FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint32_t fps)
+FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height,
+uint32_t fps)
{
int pipefd[2];
if (pipe(pipefd) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: Could not create a pipe: %s", strerror(errno));
+ TraceLog(LOG_ERROR, "FFMPEG: Could not create a pipe: %s",
+ strerror(errno));
return NULL;
}
@@ -21,7 +23,8 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
if (child < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: could not fork a child: %s", strerror(errno));
+ TraceLog(LOG_ERROR, "FFMPEG: could not fork a child: %s",
+ strerror(errno));
return NULL;
}
@@ -29,14 +32,18 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
{
if (dup2(pipefd[READ_END], STDIN_FILENO) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG CHILD: could not reopen read end of pipe as stdin: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG CHILD: could not reopen read end of pipe as stdin: %s",
+ strerror(errno));
exit(1);
}
close(pipefd[WRITE_END]);
char resolution[64];
- snprintf(resolution, sizeof(resolution), "%zux%zu", (size_t)width, (size_t)height);
+ snprintf(resolution, sizeof(resolution), "%zux%zu", (size_t)width,
+ (size_t)height);
char framerate[64];
snprintf(framerate, sizeof(framerate), "%zu", (size_t)fps);
@@ -61,7 +68,10 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
if (ret < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG CHILD: could not run ffmpeg as a child process: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG CHILD: could not run ffmpeg as a child process: %s",
+ strerror(errno));
exit(1);
}
@@ -71,7 +81,10 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
if (close(pipefd[READ_END]) < 0)
{
- TraceLog(LOG_WARNING, "FFMPEG: could not close read end of the pipe on the parent's end: %s", strerror(errno));
+ TraceLog(
+ LOG_WARNING,
+ "FFMPEG: could not close read end of the pipe on the parent's end:%s",
+ strerror(errno));
}
FFMPEG* ffmpeg = malloc(sizeof(FFMPEG));
@@ -81,13 +94,18 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
return ffmpeg;
}
-int ffmpegSendFrame(FFMPEG* ffmpeg, void* data, uint32_t width, uint32_t height)
+int ffmpegSendFrame(FFMPEG* ffmpeg, void* data, uint32_t width, uint32_t
+height)
{
for (uint32_t y = height; y > 0; --y)
{
- if (write(ffmpeg->pipe, (uint32_t*)data + (y - 1) * width, sizeof(uint32_t) * width) < 0)
+ if (write(ffmpeg->pipe, (uint32_t*)data + (y - 1) * width,
+ sizeof(uint32_t) * width) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: failed to write into ffmpeg pipe: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: failed to write into ffmpeg pipe: %s",
+ strerror(errno));
return -1;
}
}
@@ -104,7 +122,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (close(pipe) < 0)
{
- TraceLog(LOG_WARNING, "FFMPEG: could not close write end of the pipe on the parent's end: %s", strerror(errno));
+ TraceLog(
+ LOG_WARNING,
+ "FFMPEG: could not close write end of the pipe on the parent's end:%s",
+ strerror(errno));
}
if (cancel)
@@ -118,7 +139,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (waitpid(pid, &wstatus, 0) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: could not wait for ffmpeg child process to finish: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: could not wait for ffmpeg child process to finish:%s",
+ strerror(errno));
return -1;
}
@@ -128,7 +152,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (exit_status != 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: ffmpeg exited with code %d", exit_status);
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: ffmpeg exited with code %d",
+ exit_status);
return -1;
}
@@ -137,7 +164,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (WIFSIGNALED(wstatus))
{
- TraceLog(LOG_ERROR, "FFMPEG: ffmpeg got terminated by %s", strsignal(WTERMSIG(wstatus)));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: ffmpeg got terminated by %s",
+ strsignal(WTERMSIG(wstatus)));
return -1;
}
}