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