Skip to content

Instantly share code, notes, and snippets.

@Noah-Huppert
Last active July 14, 2024 21:23
Show Gist options
  • Save Noah-Huppert/9164bc4f73460cc09f62b063d55b6efc to your computer and use it in GitHub Desktop.
Save Noah-Huppert/9164bc4f73460cc09f62b063d55b6efc to your computer and use it in GitHub Desktop.
Restream A Livestream For Emby

Overview

Restream a live stream for Emby on Kubernetes.

If a live stream isn't being imported properly into Emby sometimes restreaming it can fix the issue. The setup is as follows:

  1. Nginx RTMP server
  2. ffmpeg container pulling down original stream and sending it to RTMP server
  3. m3u8 file pointing to RTMP server

Instructions

Apply the following manifests:

  1. Create a rtmp namespace
  2. RTMP server:
  • Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rtmp
  namespace: rtmp
  labels:
    app: rtmp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rtmp
  template:
    metadata:
      labels:
        app: rtmp
    spec:
      containers:
      - name: rtmp
        image: tiangolo/nginx-rtmp:latest-2020-08-16
        ports:
        - containerPort: 1935
  • Service:
apiVersion: v1
kind: Service
metadata:
  name: rtmp
  namespace: rtmp
spec:
  selector:
    app: rtmp
  ports:
  - protocol: TCP
    port: 1935
    targetPort: 1935
  type: LoadBalancer
  1. Start a container to restream using ffmpeg
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ffmpeg
  namespace: rtmp
  labels:
    app: ffmpeg
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ffmpeg
  template:
    metadata:
      labels:
        app: ffmpeg
    spec:
      containers:
      - name: rtmp
        image: linuxserver/ffmpeg:7.0.1
        args:
          - -re
          - -i
          - <SOURCE m3u8 FILE URL>
          - -c:v
          - copy
          - -f
          - flv
          - rtmp://<SERVICE LOAD BALANCER IP>/live

Be sure to replace the <SOURCE m3u8 FILE URL> with your own.
Also be sure to replace <SERVICE LOAD BALANACER> with the external IP of the rtmp service.

  1. Then create an m3u8 file pointing towards your RTMP server:
#EXTM3U
#EXTINF:-1, <STREAM TITLE>
rtmp://<SERVICE LOAD BALANCER IP>/live

Be sure to replace <SERVICE LOAD BALANACER> with the external IP of the rtmp service.

  1. Add this m3u8 file to your Emby server

Potential Improvements

Might be able to avoid needing the service load balancer IP if we use the internal Kubernetes service discovery DNS name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment