mirror of
https://github.com/hsnks100/liveflow.git
synced 2025-09-27 04:26:24 +08:00
build(docker): update Dockerfile and add FFmpeg installation script with Leak Sanitizer support (#14)
- modify Dockerfile to include static files and create videos directory - update docker-compose to change UDP port range - add install-ffmpeg-lsan.sh for FFmpeg installation with Leak Sanitizer - create lsan.Dockerfile for building with Leak Sanitizer
This commit is contained in:
@@ -10,12 +10,10 @@ ENV PKG_CONFIG_PATH=/ffmpeg_build/lib/pkgconfig:${PKG_CONFIG_PATH}
|
|||||||
ENV PATH="/usr/local/go/bin:${PATH}"
|
ENV PATH="/usr/local/go/bin:${PATH}"
|
||||||
COPY ./ /app
|
COPY ./ /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN ls .
|
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
RUN go build -o /app/bin/liveflow
|
RUN go build -o /app/bin/liveflow
|
||||||
RUN cp config.toml /app/bin/config.toml
|
RUN cp config.toml /app/bin/config.toml
|
||||||
RUN cp index.html /app/bin/index.html
|
RUN cp -r static /app/bin/static
|
||||||
|
RUN mkdir -p /app/bin/videos
|
||||||
RUN mkdir /app/bin/videos
|
|
||||||
WORKDIR /app/bin
|
WORKDIR /app/bin
|
||||||
ENTRYPOINT ["/app/bin/liveflow"]
|
ENTRYPOINT ["/app/bin/liveflow"]
|
||||||
|
@@ -5,7 +5,7 @@ port = 1930
|
|||||||
llhls = false
|
llhls = false
|
||||||
disk_ram = true
|
disk_ram = true
|
||||||
[docker]
|
[docker]
|
||||||
mode = false
|
mode=false
|
||||||
[mp4]
|
[mp4]
|
||||||
record=false
|
record=false
|
||||||
[ebml]
|
[ebml]
|
||||||
|
@@ -10,7 +10,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "8044:8044"
|
- "8044:8044"
|
||||||
- "1930:1930"
|
- "1930:1930"
|
||||||
- "30000-31000:30000-31000/udp"
|
- "40000-41000:40000-41000/udp"
|
||||||
environment:
|
environment:
|
||||||
DOCKER_MODE: "true"
|
DOCKER_MODE: "true"
|
||||||
build:
|
build:
|
||||||
|
41
install-ffmpeg-lsan.sh
Normal file
41
install-ffmpeg-lsan.sh
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Leak Sanitizer flags
|
||||||
|
export SANITIZE_FLAGS="-fsanitize=address -g -O1"
|
||||||
|
|
||||||
|
mkdir -p /ffmpeg_build
|
||||||
|
cd /ffmpeg_build
|
||||||
|
|
||||||
|
git config --global http.sslVerify false
|
||||||
|
|
||||||
|
git clone --depth 1 https://code.videolan.org/videolan/x264.git
|
||||||
|
cd x264
|
||||||
|
./configure --prefix="/ffmpeg_build" --enable-static --disable-opencl LDFLAGS="$SANITIZE_FLAGS"
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
wget --no-check-certificate -O ffmpeg-7.0.1.tar.bz2 https://ffmpeg.org/releases/ffmpeg-7.0.1.tar.bz2
|
||||||
|
tar xjf ffmpeg-7.0.1.tar.bz2
|
||||||
|
cd ffmpeg-7.0.1
|
||||||
|
|
||||||
|
PKG_CONFIG_PATH="/ffmpeg_build/lib/pkgconfig" ./configure \
|
||||||
|
--prefix="/ffmpeg_build" \
|
||||||
|
--pkg-config-flags="--static" \
|
||||||
|
--extra-cflags="-I/ffmpeg_build/include" \
|
||||||
|
--extra-ldflags="$SANITIZE_FLAGS -L/ffmpeg_build/lib" \
|
||||||
|
--extra-libs="-lpthread -lm" \
|
||||||
|
--bindir="/usr/local/bin" \
|
||||||
|
--enable-gpl \
|
||||||
|
--enable-libx264 \
|
||||||
|
--enable-nonfree
|
||||||
|
make -j8
|
||||||
|
make install
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
rm -rf /ffmpeg_build/src /ffmpeg_build/*.tar.bz2
|
||||||
|
|
||||||
|
echo "FFmpeg 7.0.1 with x264 (LSan enabled) has been successfully installed to /ffmpeg_build."
|
24
lsan.Dockerfile
Normal file
24
lsan.Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
FROM golang:1.21-bullseye
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get upgrade -y && \
|
||||||
|
apt-get install -y build-essential git pkg-config libunistring-dev libaom-dev libdav1d-dev bzip2 nasm wget yasm ca-certificates
|
||||||
|
|
||||||
|
COPY install-ffmpeg-lsan.sh /install-ffmpeg-lsan.sh
|
||||||
|
RUN chmod +x /install-ffmpeg-lsan.sh && /install-ffmpeg-lsan.sh
|
||||||
|
|
||||||
|
ENV PKG_CONFIG_PATH=/ffmpeg_build/lib/pkgconfig:${PKG_CONFIG_PATH}
|
||||||
|
ENV PATH="/usr/local/go/bin:${PATH}"
|
||||||
|
|
||||||
|
COPY ./ /app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV CGO_LDFLAGS='-fsanitize=address'
|
||||||
|
ENV CGO_CFLAGS='-fsanitize=address'
|
||||||
|
RUN go mod download
|
||||||
|
RUN go build -o /app/bin/liveflow
|
||||||
|
RUN cp config.toml /app/bin/config.toml
|
||||||
|
RUN cp -r static /app/bin/static
|
||||||
|
RUN mkdir -p /app/bin/videos
|
||||||
|
WORKDIR /app/bin
|
||||||
|
ENTRYPOINT ["/app/bin/liveflow"]
|
7
main.go
7
main.go
@@ -3,15 +3,16 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof" // pprof을 사용하기 위한 패키지
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"liveflow/config"
|
"liveflow/config"
|
||||||
"liveflow/media/streamer/egress/hls"
|
"liveflow/media/streamer/egress/hls"
|
||||||
"liveflow/media/streamer/egress/record/mp4"
|
"liveflow/media/streamer/egress/record/mp4"
|
||||||
"liveflow/media/streamer/egress/record/webm"
|
"liveflow/media/streamer/egress/record/webm"
|
||||||
"liveflow/media/streamer/egress/whep"
|
"liveflow/media/streamer/egress/whep"
|
||||||
"liveflow/media/streamer/ingress/whip"
|
"liveflow/media/streamer/ingress/whip"
|
||||||
"net/http"
|
|
||||||
_ "net/http/pprof" // pprof을 사용하기 위한 패키지
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
package hub
|
package hub
|
||||||
|
|
||||||
|
// #include <stdio.h>
|
||||||
|
// #include <stdlib.h>
|
||||||
|
//
|
||||||
|
// void __lsan_do_leak_check(void);
|
||||||
|
import "C"
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -122,6 +127,7 @@ func (h *Hub) Unpublish(streamID string) {
|
|||||||
close(ch)
|
close(ch)
|
||||||
}
|
}
|
||||||
delete(h.streams, streamID)
|
delete(h.streams, streamID)
|
||||||
|
//checkLeak()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe : Subscribes to the given streamID.
|
// Subscribe : Subscribes to the given streamID.
|
||||||
@@ -151,3 +157,11 @@ func (h *Hub) RemoveStream(streamID string) {
|
|||||||
delete(h.streams, streamID)
|
delete(h.streams, streamID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func checkLeak() {
|
||||||
|
// go func() {
|
||||||
|
// fmt.Println("will check leak")
|
||||||
|
// time.Sleep(3 * time.Second)
|
||||||
|
// C.__lsan_do_leak_check()
|
||||||
|
// }()
|
||||||
|
//}
|
||||||
|
@@ -5,11 +5,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"liveflow/media/streamer/egress/record"
|
|
||||||
"liveflow/media/streamer/processes"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"liveflow/media/streamer/egress/record"
|
||||||
|
"liveflow/media/streamer/processes"
|
||||||
|
|
||||||
astiav "github.com/asticode/go-astiav"
|
astiav "github.com/asticode/go-astiav"
|
||||||
"github.com/deepch/vdk/codec/aacparser"
|
"github.com/deepch/vdk/codec/aacparser"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -122,6 +123,7 @@ func (m *MP4) Start(ctx context.Context, source hub.Source) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ctx, err, "failed to write trailer")
|
log.Error(ctx, err, "failed to write trailer")
|
||||||
}
|
}
|
||||||
|
log.Info(ctx, "mp4 file closed")
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,10 @@ package whep
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"liveflow/media/streamer/processes"
|
|
||||||
|
|
||||||
astiav "github.com/asticode/go-astiav"
|
"github.com/asticode/go-astiav"
|
||||||
|
|
||||||
|
"liveflow/media/streamer/processes"
|
||||||
|
|
||||||
"github.com/deepch/vdk/codec/aacparser"
|
"github.com/deepch/vdk/codec/aacparser"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"liveflow/log"
|
"liveflow/log"
|
||||||
"liveflow/media/streamer/pipe"
|
"liveflow/media/streamer/pipe"
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ func (t *AudioTranscodingProcess) Init() error {
|
|||||||
if t.encCodecContext == nil {
|
if t.encCodecContext == nil {
|
||||||
return errors.New("codec context is nil")
|
return errors.New("codec context is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.decCodecContext.MediaType() == astiav.MediaTypeAudio {
|
if t.decCodecContext.MediaType() == astiav.MediaTypeAudio {
|
||||||
t.encCodecContext.SetChannelLayout(astiav.ChannelLayoutStereo)
|
t.encCodecContext.SetChannelLayout(astiav.ChannelLayoutStereo)
|
||||||
t.encCodecContext.SetSampleRate(t.encSampleRate)
|
t.encCodecContext.SetSampleRate(t.encSampleRate)
|
||||||
|
Reference in New Issue
Block a user