mirror of
https://github.com/saily/vnc-recorder.git
synced 2025-09-26 12:43:00 +00:00
some little fixes
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -15,3 +15,5 @@ vnc-recorder
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
/vendor
|
||||
|
||||
.DS_Store
|
||||
|
@@ -17,6 +17,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func encodePPMforRGBA(w io.Writer, img *image.RGBA) error {
|
||||
@@ -126,6 +127,7 @@ func (enc *X264ImageCustomEncoder) Init(videoFileName string) {
|
||||
"-an", // no audio
|
||||
"-y",
|
||||
"-i", "-",
|
||||
"-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
||||
"-vcodec", "libx264",
|
||||
"-preset", "veryfast",
|
||||
"-g", "250",
|
||||
@@ -157,15 +159,17 @@ func (enc *X264ImageCustomEncoder) Run(videoFileName string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (enc *X264ImageCustomEncoder) Encode(img image.Image) {
|
||||
func (enc *X264ImageCustomEncoder) Encode(img image.Image) error {
|
||||
if enc.input == nil || enc.closed {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
err := encodePPM(enc.input, img)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("error while encoding image.")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (enc *X264ImageCustomEncoder) Close() {
|
||||
@@ -177,5 +181,6 @@ func (enc *X264ImageCustomEncoder) Close() {
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("could not close input.")
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
}
|
||||
|
19
main.go
19
main.go
@@ -147,6 +147,7 @@ func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context, outfileName strin
|
||||
cchServer := make(chan vnc.ServerMessage)
|
||||
cchClient := make(chan vnc.ClientMessage)
|
||||
errorCh := make(chan error)
|
||||
errorCh2 := make(chan error)
|
||||
|
||||
var secHandlers []vnc.SecurityHandler
|
||||
|
||||
@@ -221,7 +222,11 @@ func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context, outfileName strin
|
||||
for {
|
||||
timeStart := time.Now()
|
||||
|
||||
vcodec.Encode(screenImage.Image)
|
||||
err := vcodec.Encode(screenImage.Image)
|
||||
if err != nil {
|
||||
errorCh2<-err
|
||||
return
|
||||
}
|
||||
|
||||
timeTarget := timeStart.Add((1000 / time.Duration(vcodec.Framerate)) * time.Millisecond)
|
||||
timeLeft := timeTarget.Sub(time.Now())
|
||||
@@ -248,6 +253,9 @@ func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context, outfileName strin
|
||||
select {
|
||||
case err := <-errorCh:
|
||||
panic(err)
|
||||
case err := <-errorCh2:
|
||||
logrus.WithField("error", err).Error("Encoded error received.")
|
||||
vcodec.Close()
|
||||
case msg := <-cchClient:
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"messageType": msg.Type(),
|
||||
@@ -272,8 +280,6 @@ func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context, outfileName strin
|
||||
if signal != nil {
|
||||
logrus.WithField("signal", signal).Info("signal received.")
|
||||
vcodec.Close()
|
||||
// give some time to write the file
|
||||
time.Sleep(time.Second * 1)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
@@ -325,8 +331,11 @@ func recorder(c *cli.Context) error {
|
||||
if c.Int("splitfile") > 0 {
|
||||
ticker := time.NewTicker(time.Duration(c.Int("splitfile")) * time.Minute)
|
||||
|
||||
go vcodecRun(vcodec, c, outfileName)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
vcodecRun(vcodec, c, outfileName)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case _ = <-ticker.C:
|
||||
|
Reference in New Issue
Block a user