Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
added support for custom gstreamer pipeline (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricomarchesin authored and Ullaakut committed Oct 12, 2018
1 parent 07e3b03 commit 110db03
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ docker run --rm \
[-e INPUT=your_input] \
[-e ENABLE_TIME_OVERLAY=true|false] \
[-e RTSP_AUTHENTICATION_METHOD=digest|basic] \
[-e GST_PIPELINE=your_custom_gstreamer_pipelime] \
[-e GST_DEBUG=your_debug_level] \
ullaakut/rtspatt
```
Expand All @@ -63,9 +64,10 @@ docker run --rm \
[-p rtsp_password] \
[-s rtsp_resolution] \
[-f rtsp_framerate] \
[-i input]
[-t] \
[-d] \
[-i input]
[-g gstreamer_pipeline] \
```

To have GStreamer debug while using the binary, simply run `export GST_DEBUG=your_debug_level` before using RTSP All The Things.
Expand Down Expand Up @@ -95,6 +97,8 @@ All of these environment variables and command line arguments override the defau
If the environment variable is set to true or the command line flag is used, a time overlay will be added to the stream. This can be useful to debug latency. [default: disabled] - RTSPATT will have to do encoding to add the time (Increased CPU usage)
* `RTSP_AUTHENTICATION_METHOD` | `-d`:
If RTSP_AUTHENTICATION_METHOD is set to `digest` or the command line flag is used, the authentication will be done using digest instead of basic auth. [default: basic]
* `GST_PIPELINE`:
Completely override the gstreamer pipeline usually autogenerated by the program. Remember though: with great power comes great responsibility! Gstreamer pipelines are a powerful tool but you need to thoroughly understand what you are doing, as things get messy easily (_see [this link](https://gstreamer.freedesktop.org/documentation/application-development/introduction/basics.html) for more information on this variable_)
* `GST_DEBUG`:
The desired debug level for GStreamer [default: none] (_see [this link](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html) for more information on this variable_)

Expand Down Expand Up @@ -128,6 +132,10 @@ All of these environment variables and command line arguments override the defau
`docker run --rm -e INPUT="/tmp/video.avi" -e RTSP_ADDRESS=172.100.100.12 -e RTSP_PORT=18554 -v "/path/to/your/video:/tmp/video.avi" -p 18554:18554 ullaakut/rtspatt` or `./rtspatt -i /tmp/video.avi -l 172.100.100.12 -b 18554`

> Serve am H264 video file without transcoding:
`docker run --rm -e INPUT="/tmp/video.mp4" -e RTSP_PORT=18554 -e "filesrc location=/tmp/video.mp4 ! qtdemux ! video/x-h264 ! rtph264pay pt=96 name=pay0" -v "/path/to/your/video:/tmp/video.mp4" -p 18554:18554 ullaakut/rtspatt`

## Build

You can modify RTSPATT and create your own docker image. For this simply run:
Expand Down
4 changes: 4 additions & 0 deletions include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define DEFAULT_HEIGHT "720"
#define DEFAULT_TIME_ENABLED false
#define DEFAULT_DIGEST_ENABLED false
#define DEFAULT_GST_PIPELINE ""

enum InputType { UNDEFINED_INPUT, FILE_INPUT, RTSP_INPUT, VIDEOTESTSRC_INPUT, DEVICE_INPUT };

Expand All @@ -51,6 +52,9 @@ typedef struct s_config {
// Options
bool time;
bool digest;

// Custom gstreamer pipeline
std::string pipeline;
} t_config;

typedef struct s_server {
Expand Down
18 changes: 15 additions & 3 deletions src/parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,19 @@ void parse_env(std::shared_ptr<t_config> &config) {
config->digest = false;
}
}

// Pipeline
config->pipeline = DEFAULT_GST_PIPELINE;
if (const char *pipeline = std::getenv("GST_PIPELINE")) {
config->pipeline = pipeline;
}
}

// Overwrite default parameters via cmd line
bool parse_args(std::shared_ptr<t_config> &config, int argc, char **argv) {
int c;
opterr = 0;
while ((c = getopt(argc, argv, "r:u:l:p:b:f:s:i:ht")) != -1) {
while ((c = getopt(argc, argv, "r:u:l:p:b:f:s:i:g:ht")) != -1) {
switch (c) {
case 'r': // Route
if (optarg && optarg[0] == '-') {
Expand Down Expand Up @@ -173,17 +179,23 @@ bool parse_args(std::shared_ptr<t_config> &config, int argc, char **argv) {
case 'd': // Use digest instead of basic auth
config->digest = true;
break;
case 'g': // Force custom gstreamer pipeline
if (optarg && optarg[0] == '-') {
break;
}
config->pipeline = optarg;
break;
case 'h': // help
fprintf(stdout,
"Usage: %s [-l address] [-b port] [-r route] [-i "
"input] [-u username] [-p password] [-f framerate] [-s "
"'width'x'height'] [-d] [-t] [-h]\n",
"'width'x'height'] [-d] [-t] [-h] [-g gst-pipeline]\n",
argv[0]);
return true;
case '?':
if (optopt == 'r' || optopt == 'l' || optopt == 'p' || optopt == 'u' ||
optopt == 'i' || optopt == 'a' || optopt == 'b' || optopt == 'f' ||
optopt == 's') {
optopt == 's' || optopt == 'g') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else if (isprint(optopt)) {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down
23 changes: 14 additions & 9 deletions src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,22 @@ std::string create_device_input(std::shared_ptr<t_config> &config) {
std::string create_pipeline(std::shared_ptr<t_config> &config) {
std::string launchCmd = "( ";

if (config->input_type == RTSP_INPUT) {
launchCmd += create_rtsp_input(config);
} else if (config->input_type == VIDEOTESTSRC_INPUT) {
launchCmd += create_videotestsrc_input(config);
} else if (config->input_type == FILE_INPUT) {
launchCmd += create_file_input(config);
} else if (config->input_type == DEVICE_INPUT) {
launchCmd += create_device_input(config);
if (config->pipeline != "") {
launchCmd += config->pipeline;
} else {
if (config->input_type == RTSP_INPUT) {
launchCmd += create_rtsp_input(config);
} else if (config->input_type == VIDEOTESTSRC_INPUT) {
launchCmd += create_videotestsrc_input(config);
} else if (config->input_type == FILE_INPUT) {
launchCmd += create_file_input(config);
} else if (config->input_type == DEVICE_INPUT) {
launchCmd += create_device_input(config);
}

launchCmd += " ! rtph264pay name=pay0 pt=96 ";
}

launchCmd += " ! rtph264pay name=pay0 pt=96 ";
launchCmd += " )";
return launchCmd;
}

0 comments on commit 110db03

Please sign in to comment.