From b3cd080e146b1cf33db5241d918ac052f5b4c30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Verstraeten?= Date: Fri, 6 Jun 2025 15:14:45 +0000 Subject: [PATCH] Refactor Dockerfile and main.go to enhance build process and streamline video handling --- Dockerfile | 16 +++------------- machinery/.DS_Store | Bin 0 -> 8196 bytes machinery/src/capture/main.go | 35 ++++++++++++++-------------------- 3 files changed, 17 insertions(+), 34 deletions(-) create mode 100644 machinery/.DS_Store diff --git a/Dockerfile b/Dockerfile index 165a3cc..a5e6ab1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,9 +32,11 @@ RUN cat /go/src/github.com/kerberos-io/agent/machinery/version ################## # Build Machinery +ENV TAGS="timetzdata netgo osusergo" +ENV LDFLAGS="-s -w -extldflags '-static -latomic'" RUN cd /go/src/github.com/kerberos-io/agent/machinery && \ go mod download && \ - go build -tags timetzdata,netgo,osusergo --ldflags '-s -w -extldflags "-static -latomic"' main.go && \ + CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$LDFLAGS" -trimpath main.go && \ mkdir -p /agent && \ mv main /agent && \ mv version /agent && \ @@ -59,18 +61,6 @@ RUN cp -r /agent ./ RUN /dist/agent/main version -############################################### -# Build Bento4 -> we want fragmented mp4 files - -ENV BENTO4_VERSION 1.6.0-641 -RUN cd /tmp && git clone https://github.com/axiomatic-systems/Bento4 && cd Bento4 && \ - git checkout tags/v${BENTO4_VERSION} && \ - cd Build && \ - cmake -DCMAKE_BUILD_TYPE=Release .. && \ - make && \ - mv /tmp/Bento4/Build/mp4fragment /dist/agent/ && \ - rm -rf /tmp/Bento4 - FROM node:18.14.0-alpine3.16 AS build-ui RUN apk update && apk upgrade --available && sync diff --git a/machinery/.DS_Store b/machinery/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0d6ac082586c9333d6a7212ad22fe40813c3494f GIT binary patch literal 8196 zcmeI1&2AD=6vuzJU>VXhVPTWT#7N?{BEvUvV`*75Q5VJNLJiJz2qnS{VW2FUChpZ& z@D+?(-$UQUmFC_%7-pcRx@z?P2sty{|2g+_?#vkg(VBTS>;e|r=C)XiESKLEHlkm4 z00B90nbD_<%V0%qFc=I5gW)Y)lYfU{Od>!YHEb4G*qkXc%&=$ zu1rJqtWFtQjaVYmO7GHmI81TkHS#GjGrx51JRC{3bS1=^L9FD`Rb0 zuR5o}yfbyCv#{k%UdXejK`?X|$Bz4K(3^L2HxB}T>J0qeL^%w+p6g6rJ|FmAFmDAj z-wTy*RA6PTY&Uo7{Jd1JHTUxM>cw9E+_o##y}Vtn6fZ8a*3RAg501NUh9f_Cub1j# zvu8W8bUz?(IZ@BgIum~w_T|*)MaYDccq`I(5~>U#a~%2<2sw?b)%sk%jxDD22$@n)US|otT&K(WZDx$4neA~; zkNCQp)LbrmrkKl5JieOAWtG8T(4@54mHB_0OW*$+42FLgkv{AkwxY+Ub;w*>=F_jE ZLYagA?nQuD`omCYS82_Q0E6M0@Dp=XO@jac literal 0 HcmV?d00001 diff --git a/machinery/src/capture/main.go b/machinery/src/capture/main.go index 9d9d542..8633906 100644 --- a/machinery/src/capture/main.go +++ b/machinery/src/capture/main.go @@ -299,10 +299,6 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat // If this happens we need to check to properly close the recording. if cursorError != nil { if recordingStatus == "started" { - // This will write the trailer a well. - if err := myMuxer.WriteTrailer(); err != nil { - log.Log.Error(err.Error()) - } log.Log.Info("capture.main.HandleRecordStream(continuous): Recording finished: file save: " + name) @@ -395,24 +391,21 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat // Running... log.Log.Info("capture.main.HandleRecordStream(motiondetection): recording started") - file, _ = os.Create(fullName) - myMuxer, _ = mp4.CreateMp4Muxer(file) - // Check which video codec we need to use. - videoSteams, _ := rtspClient.GetVideoStreams() - for _, stream := range videoSteams { - width := configuration.Config.Capture.IPCamera.Width - height := configuration.Config.Capture.IPCamera.Height - widthOption := mp4.WithVideoWidth(uint32(width)) - heightOption := mp4.WithVideoHeight(uint32(height)) - if stream.Name == "H264" { - videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H264, widthOption, heightOption) - } else if stream.Name == "H265" { - videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H265, widthOption, heightOption) - } - } - // For an MP4 container, AAC is the only audio codec supported. - audioTrack = myMuxer.AddAudioTrack(mp4.MP4_CODEC_AAC) + // Get width and height from the camera. + width := configuration.Config.Capture.IPCamera.Width + height := configuration.Config.Capture.IPCamera.Height + + // Get SPS and PPS NALUs from the camera. + spsNALUS := configuration.Config.Capture.IPCamera.SPSNALUs + ppsNALUS := configuration.Config.Capture.IPCamera.PPSNALUs + vpsNALUS := configuration.Config.Capture.IPCamera.VPSNALUs + + // Create a video file, and set the dimensions. + mp4Video := video.NewMP4(fullName, spsNALUS, ppsNALUS, vpsNALUS) + mp4Video.SetWidth(width) + mp4Video.SetHeight(height) + start := false // Get as much packets we need.