Commit a65b5ab0 authored by Julian Rother's avatar Julian Rother

Added variable expansion for strings and enabled it for filter graphs in "transcode"

parent eea5ba38
Pipeline #1197 passed with stage
in 8 minutes and 35 seconds
...@@ -23,7 +23,7 @@ static void setup_input_stream(char *stream, AVFormatContext *demux, ...@@ -23,7 +23,7 @@ static void setup_input_stream(char *stream, AVFormatContext *demux,
AVCodecContext **decs, AVFilterGraph *fg, AVFilterContext **srcs, AVCodecContext **decs, AVFilterGraph *fg, AVFilterContext **srcs,
AVFilterInOut **pads) AVFilterInOut **pads)
{ {
char *p; char *p, *tmp;
int idx, err; int idx, err;
enum AVMediaType type; enum AVMediaType type;
AVDictionary *opts; AVDictionary *opts;
...@@ -83,8 +83,9 @@ static void setup_input_stream(char *stream, AVFormatContext *demux, ...@@ -83,8 +83,9 @@ static void setup_input_stream(char *stream, AVFormatContext *demux,
for (p = jenter(jlookup(stream, "filters")); p; p = jnext(p)) for (p = jenter(jlookup(stream, "filters")); p; p = jnext(p))
{ {
(*pads)->name = av_strdup("in"); (*pads)->name = av_strdup("in");
if ((err = avfilter_graph_parse_ptr(fg, jstr(p, "ERROR"), 0, pads, 0)) < 0) tmp = eval_vars(jstr(p, "ERROR"));
job_failed("Parsing filter string \"%s\" failed: %s", jstr(p, 0), av_err2str(err)); if ((err = avfilter_graph_parse_ptr(fg, tmp, 0, pads, 0)) < 0)
job_failed("Parsing filter string \"%s\" failed: %s", tmp, av_err2str(err));
if ((*pads)->next) if ((*pads)->next)
job_failed("Unconnected filter pad\n"); job_failed("Unconnected filter pad\n");
} }
...@@ -96,7 +97,7 @@ static void prepare_output_stream(char *stream, AVStream *st, ...@@ -96,7 +97,7 @@ static void prepare_output_stream(char *stream, AVStream *st,
AVFilterInOut **pads) AVFilterInOut **pads)
{ {
int idx, err; int idx, err;
char *p; char *p, *tmp;
AVFilterInOut *_inpads; AVFilterInOut *_inpads;
AVFilterInOut *_outpads; AVFilterInOut *_outpads;
idx = st->index; idx = st->index;
...@@ -138,8 +139,9 @@ static void prepare_output_stream(char *stream, AVStream *st, ...@@ -138,8 +139,9 @@ static void prepare_output_stream(char *stream, AVStream *st,
for (p = jenter(jlookup(stream, "filters")); p; p = jnext(p)) for (p = jenter(jlookup(stream, "filters")); p; p = jnext(p))
{ {
(*pads)->name = av_strdup("out"); (*pads)->name = av_strdup("out");
if ((err = avfilter_graph_parse_ptr(fg, jstr(p, "ERROR"), pads, 0, 0)) < 0) tmp = eval_vars(jstr(p, "ERROR"));
job_failed("Parsing filter string \"%s\" failed: %s", jstr(p, 0), av_err2str(err)); if ((err = avfilter_graph_parse_ptr(fg, tmp, pads, 0, 0)) < 0)
job_failed("Parsing filter string \"%s\" failed: %s", tmp, av_err2str(err));
if ((*pads)->next) if ((*pads)->next)
job_failed("Unconnected filter pad\n"); job_failed("Unconnected filter pad\n");
} }
......
...@@ -19,6 +19,7 @@ char *json_fileinfo(char *path); ...@@ -19,6 +19,7 @@ char *json_fileinfo(char *path);
void overwrite_check(char *path, char *srcpath, char *srchash); void overwrite_check(char *path, char *srcpath, char *srchash);
int checktime(time_t min); int checktime(time_t min);
char *buildpath(char *root, char *path); char *buildpath(char *root, char *path);
char *eval_vars(char *p);
#define WORKER_APIKEY "WORKER_APIKEY" #define WORKER_APIKEY "WORKER_APIKEY"
#define WORKER_APIBASE "WORKER_APIBASE" #define WORKER_APIBASE "WORKER_APIBASE"
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../util.h"
char *eval_vars(char *p)
{
char *ptr;
size_t size;
FILE *stream;
if (!(stream = open_memstream(&ptr, &size)))
exit(99);
for (; *p; p ++)
{
if (!strncmp(p, SL("$" WORKER_RAW)))
{
p += sizeof(WORKER_RAW)-1;
if (getenv(WORKER_RAW))
fputs(getenv(WORKER_RAW), stream);
}
else if (!strncmp(p, SL("$" WORKER_RELEASED)))
{
p += sizeof(WORKER_RELEASED)-1;
if (getenv(WORKER_RELEASED))
fputs(getenv(WORKER_RELEASED), stream);
}
else if (!strncmp(p, SL("$" WORKER_TMP)))
{
p += sizeof(WORKER_TMP)-1;
if (getenv(WORKER_TMP))
fputs(getenv(WORKER_TMP), stream);
}
else
fputc(*p, stream);
}
fclose(stream);
return ptr;
}
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