now you can spit files each N minutes

This commit is contained in:
aluvare 2021-12-02 19:10:12 +01:00
parent 0aff2846b2
commit 2b01d82b97
3 changed files with 60 additions and 15 deletions

3
.gitignore vendored
View File

@ -9,7 +9,8 @@
*.test *.test
vnc-recorder vnc-recorder
output.mp4 *.mp4
*.s*
# Output of the go coverage tool, specifically when used with LiteIDE # Output of the go coverage tool, specifically when used with LiteIDE
*.out *.out

View File

@ -34,6 +34,7 @@ library which made this wrapper possible.
--framerate value Framerate to record (default: 30) [$VR_FRAMERATE] --framerate value Framerate to record (default: 30) [$VR_FRAMERATE]
--crf value Constant Rate Factor (CRF) to record with (default: 35) [$VR_CRF] --crf value Constant Rate Factor (CRF) to record with (default: 35) [$VR_CRF]
--outfile value Output file to record to. (default: "output.mp4") [$VR_OUTFILE] --outfile value Output file to record to. (default: "output.mp4") [$VR_OUTFILE]
--splitfile value Mins to split file. (default: 0) [$VR_SPLIT_OUTFILE]
--help, -h show help --help, -h show help
--version, -v print the version --version, -v print the version

71
main.go
View File

@ -14,6 +14,7 @@ import (
"path" "path"
"syscall" "syscall"
"time" "time"
"strconv"
) )
func main() { func main() {
@ -67,10 +68,16 @@ func main() {
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "outfile", Name: "outfile",
Value: "output.mp4", Value: "output",
Usage: "Output file to record to.", Usage: "Output file to record to.",
EnvVars: []string{"VR_OUTFILE"}, EnvVars: []string{"VR_OUTFILE"},
}, },
&cli.IntFlag{
Name: "splitfile",
Value: 0,
Usage: "Mins to split file.",
EnvVars: []string{"VR_SPLIT_OUTFILE"},
},
}, },
} }
@ -79,8 +86,8 @@ func main() {
} }
} }
func recorder(c *cli.Context) error { //func vcodecRun(c *cli.Context, vcodec *X264ImageCustomEncoder, ccflags *vnc.ClientConfig, screenImage *vnc.VncCanvas, vncConnection *vnc.ClientConn, errorCh chan error, cchClient chan vnc.ClientMessage, cchServer chan vnc.ServerMessage, outfile string) {
fmt.Println("PASSWORD", c.String("password")) func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context) error {
address := fmt.Sprintf("%s:%d", c.String("host"), c.Int("port")) address := fmt.Sprintf("%s:%d", c.String("host"), c.Int("port"))
dialer, err := net.DialTimeout("tcp", address, 5*time.Second) dialer, err := net.DialTimeout("tcp", address, 5*time.Second)
if err != nil { if err != nil {
@ -143,21 +150,18 @@ func recorder(c *cli.Context) error {
} }
screenImage := vncConnection.Canvas screenImage := vncConnection.Canvas
ffmpegPath, err := exec.LookPath(c.String("ffmpeg")) var outfileName string
if err != nil { outfile := c.String("outfile")
logrus.WithError(err).Error("ffmpeg binary not found.")
return err
}
logrus.WithField("ffmpeg", ffmpegPath).Info("ffmpeg binary for recording found")
vcodec := &X264ImageCustomEncoder{ if c.Int("splitfile") > 0 {
FFMpegBinPath: ffmpegPath, t := time.Now()
Framerate: c.Int("framerate"), outfileName = outfile + "-" + strconv.Itoa(t.Year()) + "-" + strconv.Itoa(int(t.Month())) + "-" + strconv.Itoa(t.Day()) + "-" + strconv.Itoa(t.Hour()) + "-" + strconv.Itoa(t.Minute())
ConstantRateFactor: c.Int("crf"), } else {
outfileName = outfile
} }
//goland:noinspection GoUnhandledErrorResult //goland:noinspection GoUnhandledErrorResult
go vcodec.Run(c.String("outfile")) go vcodec.Run(outfileName + ".mp4")
for _, enc := range ccflags.Encodings { for _, enc := range ccflags.Encodings {
myRenderer, ok := enc.(vnc.Renderer) myRenderer, ok := enc.(vnc.Renderer)
@ -239,5 +243,44 @@ func recorder(c *cli.Context) error {
} }
} }
} }
}
func recorder(c *cli.Context) error {
ffmpegPath, err := exec.LookPath(c.String("ffmpeg"))
if err != nil {
logrus.WithError(err).Error("ffmpeg binary not found.")
return err
}
logrus.WithField("ffmpeg", ffmpegPath).Info("ffmpeg binary for recording found")
vcodec := &X264ImageCustomEncoder{
FFMpegBinPath: ffmpegPath,
Framerate: c.Int("framerate"),
ConstantRateFactor: c.Int("crf"),
}
if c.Int("splitfile") > 0 {
ticker := time.NewTicker(time.Duration(c.Int("splitfile")) * time.Minute)
go vcodecRun(vcodec, c)
for {
select {
case _ = <-ticker.C:
vcodec.Close()
vcodec = &X264ImageCustomEncoder{
FFMpegBinPath: ffmpegPath,
Framerate: c.Int("framerate"),
ConstantRateFactor: c.Int("crf"),
}
go vcodecRun(vcodec, c)
}
}
} else {
vcodecRun(vcodec, c)
}
return nil return nil
} }