From c61ee5cbbcb3f47ff26dbeb8ef8b92aaf9a2108b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Mon, 13 Jan 2025 12:26:53 +0100 Subject: [PATCH] Switch livepeer_ffmpeg into the system ffmpeg --- Makefile | 3 --- cmd/livepeer_ffmpeg/livepeer_ffmpeg.go | 33 -------------------------- docker/Dockerfile | 2 +- media/rtmp2segment.go | 18 ++++++++------ server/ai_live_video.go | 14 +++++------ 5 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 cmd/livepeer_ffmpeg/livepeer_ffmpeg.go diff --git a/Makefile b/Makefile index 07950f4a6..97d0ef053 100644 --- a/Makefile +++ b/Makefile @@ -100,9 +100,6 @@ endif livepeer: GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -tags "$(BUILD_TAGS)" -ldflags="$(ldflags)" cmd/livepeer/*.go -livepeer_ffmpeg: - GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -ldflags="$(ldflags)" -ldflags="$(ldflags)" cmd/livepeer_ffmpeg/*.go - livepeer_cli: GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -tags "$(BUILD_TAGS)" -ldflags="$(ldflags)" cmd/livepeer_cli/*.go diff --git a/cmd/livepeer_ffmpeg/livepeer_ffmpeg.go b/cmd/livepeer_ffmpeg/livepeer_ffmpeg.go deleted file mode 100644 index 45f4054b3..000000000 --- a/cmd/livepeer_ffmpeg/livepeer_ffmpeg.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/livepeer/lpms/ffmpeg" -) - -func main() { - if len(os.Args) < 4 { - fmt.Println("Usage: livepeer_ffmpeg ") - os.Exit(1) - } - - in := os.Args[1] - outFilePattern := os.Args[2] - muxer := os.Args[3] - - ffmpeg.FfmpegSetLogLevel(ffmpeg.FFLogWarning) - _, err := ffmpeg.Transcode3(&ffmpeg.TranscodeOptionsIn{ - Fname: in, - }, []ffmpeg.TranscodeOptions{{ - Oname: outFilePattern, - AudioEncoder: ffmpeg.ComponentOptions{Name: "copy"}, - VideoEncoder: ffmpeg.ComponentOptions{Name: "copy"}, - Muxer: ffmpeg.ComponentOptions{Name: muxer}, - }}) - if err != nil { - fmt.Printf("Failed to run segmentation. in=%s err=%s\n", in, err) - os.Exit(1) - } -} diff --git a/docker/Dockerfile b/docker/Dockerfile index 4c112c6a7..3a6589aa0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -68,6 +68,6 @@ 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 net-tools lsof -y +RUN apt update && apt install -yqq ffmpeg ENTRYPOINT ["/usr/local/bin/livepeer"] diff --git a/media/rtmp2segment.go b/media/rtmp2segment.go index 8a36068cd..0880cac14 100644 --- a/media/rtmp2segment.go +++ b/media/rtmp2segment.go @@ -56,14 +56,18 @@ func (ms *MediaSegmenter) RunSegmentation(ctx context.Context, in string, segmen clog.Errorf(ctx, "Stopping segmentation, input stream does not exist. in=%s err=%s", in, err) break } - cmd := exec.Command("/usr/local/bin/livepeer_ffmpeg", in, outFilePattern, "segment") - _, err = cmd.CombinedOutput() + cmd := exec.Command("ffmpeg", + "-i", in, + "-c:a", "copy", + "-c:v", "copy", + "-f", "segment", + outFilePattern, + ) + output, err := cmd.CombinedOutput() if err != nil { - clog.Errorf(ctx, "Failed to run segmentation process. in=%s err=%s", in, err) - } - err = cmd.Wait() - if err != nil { - clog.Errorf(ctx, "Failed to run segmentation process. in=%s err=%s", in, err) + clog.Errorf(ctx, "Error sending RTMP out process: %v", err) + clog.Infof(ctx, "Process output: %s", output) + return } clog.Infof(ctx, "Done with segmentation process") retryCount++ diff --git a/server/ai_live_video.go b/server/ai_live_video.go index 11c512691..445066325 100644 --- a/server/ai_live_video.go +++ b/server/ai_live_video.go @@ -210,9 +210,13 @@ func startTrickleSubscribe(ctx context.Context, url *url.URL, params aiRequestPa break } - in := "pipe:0" - out := params.liveParams.outputRTMPURL - cmd := exec.Command("/usr/local/bin/livepeer_ffmpeg", in, out, "flv") + cmd := exec.Command("ffmpeg", + "-i", "pipe:0", + "-c:a", "copy", + "-c:v", "copy", + "-f", "flv", + params.liveParams.outputRTMPURL, + ) cmd.Stdin = r output, err := cmd.CombinedOutput() if err != nil { @@ -220,10 +224,6 @@ func startTrickleSubscribe(ctx context.Context, url *url.URL, params aiRequestPa clog.Infof(ctx, "Process output: %s", output) return } - err = cmd.Wait() - if err != nil { - clog.Infof(ctx, "Error sending RTMP out: %s", err) - } time.Sleep(5 * time.Second) } }()