mirror of
https://github.com/saily/vnc-recorder.git
synced 2025-07-05 01:36:19 +00:00
more fixes
This commit is contained in:
parent
84873910b7
commit
5fcd679e5e
66
main.go
66
main.go
@ -15,6 +15,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
@ -252,16 +253,23 @@ func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context, outfileName strin
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err := <-errorCh:
|
case err := <-errorCh:
|
||||||
|
if strings.Contains(err.Error(), "EOF") {
|
||||||
|
logrus.WithField("error", err).Error("Received EOF, maybe a resolution change.")
|
||||||
|
vcodec.Close()
|
||||||
|
videoUpload(c, outfileName)
|
||||||
panic(err)
|
panic(err)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
case err := <-errorCh2:
|
case err := <-errorCh2:
|
||||||
logrus.WithField("error", err).Error("Encoded error received.")
|
logrus.WithField("error", err).Error("Encoded error received.")
|
||||||
vcodec.Close()
|
vcodec.Close()
|
||||||
|
videoUpload(c, outfileName)
|
||||||
case msg := <-cchClient:
|
case msg := <-cchClient:
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"messageType": msg.Type(),
|
"messageType": msg.Type(),
|
||||||
"message": msg,
|
"message": msg,
|
||||||
}).Debug("client message received.")
|
}).Debug("client message received.")
|
||||||
|
|
||||||
case msg := <-cchServer:
|
case msg := <-cchServer:
|
||||||
if msg.Type() == vnc.FramebufferUpdateMsgType {
|
if msg.Type() == vnc.FramebufferUpdateMsgType {
|
||||||
secsPassed := time.Now().Sub(timeStart).Seconds()
|
secsPassed := time.Now().Sub(timeStart).Seconds()
|
||||||
@ -286,6 +294,62 @@ func vcodecRun(vcodec *X264ImageCustomEncoder, c *cli.Context, outfileName strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func videoUpload(c *cli.Context, outfileName string) error {
|
||||||
|
var minioClient *minio.Client
|
||||||
|
var err error
|
||||||
|
if c.String("s3_endpoint") != "" {
|
||||||
|
if c.Int("splitfile") == 0 {
|
||||||
|
return errors.New("If you want to upload videos to S3, you need to split files.")
|
||||||
|
}
|
||||||
|
minioClient, err = minio.New(c.String("s3_endpoint"), &minio.Options{
|
||||||
|
Creds: credentials.NewStaticV4(c.String("s3_accessKeyID"), c.String("s3_secretAccessKey"), ""),
|
||||||
|
Secure: c.Bool("s3_ssl"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
if c.String("s3_endpoint") != "" {
|
||||||
|
found, err := minioClient.BucketExists(context.Background(), c.String("s3_bucketName"))
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error("minioClient.BucketExists", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if ! found {
|
||||||
|
err = minioClient.MakeBucket(context.Background(), c.String("s3_bucketName"), minio.MakeBucketOptions{Region: c.String("s3_region")})
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error("minioClient.MakeBucket", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file, err := os.Open(outfileName + ".mp4")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error("os.Open", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fileStat, err := file.Stat()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error("fileStat", err)
|
||||||
|
file.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadInfo, err := minioClient.PutObject(context.Background(), c.String("s3_bucketName"), outfileName + ".mp4", file, fileStat.Size(), minio.PutObjectOptions{ContentType:"application/octet-stream"})
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error("minioClient.PutObject", err)
|
||||||
|
file.Close()
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
file.Close()
|
||||||
|
os.Remove(outfileName + ".mp4")
|
||||||
|
}
|
||||||
|
logrus.Debug("Successfully uploaded bytes: ", uploadInfo)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func recorder(c *cli.Context) error {
|
func recorder(c *cli.Context) error {
|
||||||
if c.Bool("debug") {
|
if c.Bool("debug") {
|
||||||
logrus.SetReportCaller(true)
|
logrus.SetReportCaller(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user