Commit 17eeeac6 authored by Julian Rother's avatar Julian Rother
Browse files

Added "simple_live_transcode" worker

parent 6de49420
TARGETS = probe probe-raw remux thumbnail transcode publish_video TARGETS = probe probe-raw remux thumbnail transcode publish_video simple_live_transcode
CFLAGS = -I /usr/include/libxml2 CFLAGS = -I /usr/include/libxml2
LDFLAGS= -lcurl -lavcodec -lavformat -lavfilter -lswscale -lavutil -lxml2 LDFLAGS= -lcurl -lavcodec -lavformat -lavfilter -lswscale -lavutil -lxml2
...@@ -18,5 +18,7 @@ transcode: transcode.c *.h util/*.c ...@@ -18,5 +18,7 @@ transcode: transcode.c *.h util/*.c
publish_video: publish_video.c *.h util/*.c publish_video: publish_video.c *.h util/*.c
simple_live_transcode: simple_live_transcode.c *.h util/*.c
clean: clean:
rm -f ${TARGETS} rm -f ${TARGETS}
#include <poll.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "util.h"
#define OUTPUT_FORMAT(bitrate) "-f", "flv", "-r", "25", "-c:v", "libx264", "-b:v", bitrate, "-bufsize", bitrate, "-preset", "veryfast", "-x264-params", "keyint=125:min-keyint=125:no-scenecut", "-c:a", "aac"
static void copy_to_log(int fd)
static char buf[1024];
size_t len;
if ((len = read(fd, BL(buf))) > 0)
fwrite(buf, 1, len, logstream);
int main(int argc, char *argv[])
int ret, errpipe[2] = {-1, -1};
char *src, *dest;
pid_t pid;
struct pollfd fds = {.fd = -1, .events = POLLIN};
if (argc != 5)
return 1;
jobid = atoi(argv[1]);
src = jstr(jlookup(argv[4], "src"), "rtmp://");
dest = jstr(jlookup(argv[4], "destbase"), "rtmp://");
if (!(pid = fork()))
dup2(errpipe[1], 2); close(errpipe[1]);
dup2(open("/dev/null", O_RDONLY|O_CLOEXEC), 0);
dup2(open("/dev/null", O_WRONLY|O_CLOEXEC), 1);
execlp("ffmpeg", "ffmpeg", "-nostats", "-i", src, "-filter_complex",
mprintf("[0:a]asplit=3[lowa][mida][higha]; movie=%s/video-logo-150px-trans.png,scale=w=100:h=100[logo]; [0:v]yadif,scale=1920:1080[tmp]; [tmp][logo]overlay=x=W-195:y=H-155,split=3[lowtmp][midtmp][high]; [lowtmp]scale=640:360[low]; [midtmp]scale=1280:720[mid]", getenv(WORKER_RAW)),
"-map", "[low]", "-map", "[lowa]", OUTPUT_FORMAT("512k"), mprintf("%s_low", dest),
"-map", "[mid]", "-map", "[mida]", OUTPUT_FORMAT("2024k"), mprintf("%s_mid", dest),
"-map", "[high]", "-map", "[higha]", OUTPUT_FORMAT("6024k"), mprintf("%s_high", dest), 0);
fds.fd = errpipe[0];
while (1)
ping_job(jobid, "running", "{\"log\": \"%s\"}", jescape(get_avlogbuf()));
poll(&fds, 1, 15000);
if (fds.revents & POLLIN)
else if (fds.revents & (POLLERR|POLLHUP|POLLNVAL))
waitpid(pid, &ret, 0);
if (!WEXITSTATUS(ret))
ping_job(jobid, "finished", "{\"log\": \"%s\"}", jescape(get_avlogbuf()));
else if (WIFSIGNALED(ret))
job_failed("Subprocesses was killed by signal %s (%i)", strsignal(WTERMSIG(ret)), WTERMSIG(ret));
job_failed("Subprocesses terminated with exit status %i", WEXITSTATUS(ret));
return 0;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment