Skip to content

Commit

Permalink
Add local ffmpeg and MediaMTX builds to Docker (#3353)
Browse files Browse the repository at this point in the history
This is needed in order to support Opus (enhanced RTMP)
  • Loading branch information
j0sh authored Feb 6, 2025
1 parent 86922ea commit fd6fe5c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
11 changes: 8 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ENV GOARCH="$TARGETARCH" \
CGO_LDFLAGS="-L/usr/local/cuda_${TARGETARCH}/lib64"

RUN apt update \
&& apt install -yqq software-properties-common curl apt-transport-https lsb-release yasm \
&& apt install -yqq software-properties-common curl apt-transport-https lsb-release nasm \
&& curl -fsSL https://dl.google.com/go/go1.21.5.linux-${BUILDARCH}.tar.gz | tar -C /usr/local -xz \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=${BUILDARCH}] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
Expand All @@ -30,6 +30,11 @@ RUN GRPC_HEALTH_PROBE_VERSION=v0.3.6 \
&& chmod +x /usr/bin/grpc_health_probe \
&& ldconfig /usr/local/lib

RUN FFMPEG_SHA=b76053d8bf322b197a9d07bd27bbdad14fd5bc15 git clone --depth 1 https://git.ffmpeg.org/ffmpeg.git /ffmpeg \
&& cd /ffmpeg && git fetch --depth 1 origin ${FFMPEG_SHA} \
&& git checkout ${FFMPEG_SHA} \
&& ./configure --prefix=build && make -j"$(nproc)" && make install

ENV GOPATH=/go \
GO_BUILD_DIR=/build/ \
GOFLAGS="-mod=readonly"
Expand Down Expand Up @@ -67,7 +72,7 @@ COPY --from=build /build/ /usr/local/bin/
COPY --from=build /usr/bin/grpc_health_probe /usr/local/bin/grpc_health_probe
COPY --from=build /src/tasmodel.pb /tasmodel.pb
COPY --from=build /usr/share/misc/pci.ids /usr/share/misc/pci.ids

RUN apt update && apt install -yqq ffmpeg
COPY --from=build /ffmpeg/build/ /usr/local
RUN ldconfig /usr/local/lib

ENTRYPOINT ["/usr/local/bin/livepeer"]
38 changes: 29 additions & 9 deletions docker/Dockerfile.mediamtx
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
ARG MEDIAMTX_VERSION="1.11.2-livepeer-2"

FROM golang:1.23 AS builder

# Install any build dependencies (e.g., git)
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*

# Use this branch while we have changes waiting for upstream
ARG MEDIAMTX_VERSION
WORKDIR /app
RUN git clone --branch v${MEDIAMTX_VERSION} https://github.com/livepeer/mediamtx.git .

# Download Go dependencies
RUN go mod download

# Disable CGO
ENV CGO_ENABLED=0

# Generate code and build
RUN go generate ./...
RUN go build -o mediamtx

FROM ubuntu:24.04

# we need curl in the image as it's later used in the runOnReady command
Expand All @@ -18,14 +42,10 @@ RUN mkdir -p /var/log/ \

COPY --chmod=0755 mediamtx-metrics.bash /opt/mediamtx-metrics.bash

ENV MEDIAMTX_VERSION="1.9.3"

ADD "https://github.com/bluenviron/mediamtx/releases/download/v${MEDIAMTX_VERSION}/mediamtx_v${MEDIAMTX_VERSION}_linux_amd64.tar.gz" /opt/mediamtx/mediamtx.tar.gz

RUN tar xzf /opt/mediamtx/mediamtx.tar.gz -C /opt/mediamtx/ \
&& mkdir -p /usr/local/bin /etc/mediamtx/ \
&& mv /opt/mediamtx/mediamtx /usr/local/bin/mediamtx \
&& mv /opt/mediamtx/mediamtx.yml /etc/mediamtx/mediamtx.yml \
&& rm -rf /opt/mediamtx/
# Copy artifacts from the builder stage
ARG MEDIAMTX_VERSION
ENV MEDIAMTX_VERSION=${MEDIAMTX_VERSION}
COPY --from=builder /app/mediamtx /usr/local/bin/mediamtx
COPY --from=builder /app/mediamtx.yml /etc/mediamtx/mediamtx.yml

CMD [ "/bin/bash", "-c", "declare -p >> /etc/environment && cron && /usr/local/bin/mediamtx" ]
4 changes: 2 additions & 2 deletions media/mediamtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const (
mediaMTXControlPort = "9997"
mediaMTXControlTimeout = 30 * time.Second
mediaMTXControlUser = "admin"
MediaMTXWebrtcSession = "webrtcSession"
MediaMTXRtmpConn = "rtmpConn"
MediaMTXWebrtcSession = "webrtcsession"
MediaMTXRtmpConn = "rtmpconn"
)

func MediamtxSourceTypeToString(s string) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions server/ai_mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func (ls *LivepeerServer) StartLiveVideo() http.Handler {
http.Error(w, "Missing source_type", http.StatusBadRequest)
return
}
sourceType = strings.ToLower(sourceType) // mediamtx changed casing between versions
sourceTypeStr, err := media.MediamtxSourceTypeToString(sourceType)
if err != nil {
clog.Errorf(ctx, "Invalid source type %s", sourceType)
Expand Down

0 comments on commit fd6fe5c

Please sign in to comment.