Transcoding is expensive and resource consuming operation on CPU and GPU. For big companies with thousands of customers it is essential, to have a dedicated 24/7 transcoding servers which can store all the transcoded versions.
For the rest of us who don't have infinite resources and cannot have 3 times bigger media library because of transcoding, we should only transcode when it is needed. This tool is trying to solve this problem by offering transcoding on demand.
This feature is common in media centers (plex, jellyfin) but there was no simple transcoding server without all other media center features. Now there is one! go-transcode is simple and extensible, and will probably not add features unrelated to transcoding.
Sources:
- Live streams
- Static files (basic support)
- Any codec/container supported by ffmpeg
Outputs:
- Basic MP4 over HTTP (h264+aac) :
http://go-transcode/[profile]/[stream-id]
- Basic HLS over HTTP (h264+aac) :
http://go-transcode/[profile]/[stream-id]/index.m3u8
- Demo HTML player (for HLS) :
http://go-transcode/[profile]/[stream-id]/play.html
Features:
- Seeking for static files (index)
- Audio/Subtitles tracks
- Private mode (serve users authenticated by reverse proxy)
Place your config file in ./config.yaml
(or /etc/transcode/config.yaml
). The streams are defined like this:
streams:
<stream-id>: <stream-url>
Full configuration example:
# allow debug outputs
debug: true
# mount debug pprof endpoint at /debug/pprof/
pprof: true
# bind server to IP:PORT (use :8888 for all connections)
bind: localhost:8888
# serve static files from this directory (optional)
static: /var/www/html
# TODO: issue #4
proxy: true
streams:
cam: rtmp://localhost/live/cam
ch1_hd: http://192.168.1.34:9981/stream/channelid/85
ch2_hd: http://192.168.1.34:9981/stream/channelid/43
go-transcode supports any formats that ffmpeg likes. We provide profiles out-of-the-box for h264+aac (mp4 container) for 360p, 540p, 720p and 1080p resolutions: h264_360p
, h264_540p
, h264_720p
and h264_1080p
. Profiles can have any name, but must match regex: ^[0-9A-Za-z_-]+$
In these profile directories, actual profiles are located in hls/
and http/
, depending on the output format requested. The profiles scripts detect hardware support by running ffmpeg. No special config needed to use hardware acceleration.
Clone repository and build with go compiler:
$ git clone https://github.com/m1k1o/go-transcode
$ cd go-transcode
$ go build
$ ./go-transcode serve
3:58PM WRN preflight complete without config file debug=false
3:56PM INF starting main server service=main
3:56PM INF http listening on 127.0.0.1:8080 module=http
3:56PM INF serving streams from basedir /home/klahaha/go-transcode: map[] service=main
3:56PM INF main ready service=main
First line is warning and "serving streams" line says empty list (map[]
) because we don't have config.yaml so there no stream configured. Make your config.yaml and try again.
docker build -t go-transcode:latest .
docker run --rm -d \
--name="go-transcode" \
-p "8080:8080" \
-v "${PWD}/config.yaml:/app/config.yaml" go-transcode:latest
You will need to have nvidia-docker installed.
First, you need to build previous container. Then, build Nvidia container.
docker build --build-arg "TRANSCODE_IMAGE=go-transcode:latest" -t go-transcode-nvidia:latest -f Dockerfile.nvidia .
docker run --rm -d \
--gpus=all \
--name="go-transcode-nvidia" \
-p "8080:8080" \
-v "${PWD}/config.yaml:/app/config.yaml" go-transcode-nvidia:latest
Input codec will be automatically determined from given stream. Please check your graphic card's supported codec and maximum concurrent sessions here.
Codec | CUVID | Codec Name |
---|---|---|
h264 | h264_cuvid | H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 |
hevc | hevc_cuvid | H.265 / HEVC |
mjpeg | mjpeg_cuvid | Motion JPEG |
mpeg1video | mpeg1_cuvid | MPEG-1 video |
mpeg2video | mpeg2_cuvid | MPEG-2 video |
mpeg4 | mpeg4_cuvid | MPEG-4 part 2 |
vc1 | vc1_cuvid | SMPTE VC-1 |
vp8 | vp8_cuvid | On2 VP8 |
vp9 | vp9_cuvid | Google VP9 |
- nginx-vod-module: Only supports MP4 sources.
- tvheadend: Intended for various live sources (IPTV or DVB), not media library - although it can record TV. Supports Nvidia acceleration, but it is hard to compile.
- jellyfin: Supports live TV sources, although does not work realiably. Cannot run standalone transcoding service (without media library).
- Any suggestions?
Join us in the Matrix space (or the #go-transcode-general room directly) or via XMPP bridge.
The source code is in the following files/folders:
cmd/
andmain.go
: source for the command-line interfacehls/
: process runner for HLS transcodinginternal/
: actual source code logic
TODO: document different modules/packages and dependencies
Other files/folders in the repositories are:
data/
: files used/served by go-transcodedev/
: some docker helper scriptsprofiles/
: the ffmpeg profiles for transcodingtests/
: some tests for the projectDockerfile
,Dockerfile.nvidia
anddocker-compose.yaml
: for the docker loversgod.mod
andgo.sum
: golang dependencies/modules trackingLICENSE
: licensing information (Apache 2.0)