🎥 Make videos programmatically with React
initial work on models and request
Alex Fernandezcac756a6a5b1
diff --git a/packages/goclient/.gitignore b/packages/goclient/.gitignorenew file mode 100644index 0000000000..c68131d737--- /dev/null+++ b/packages/goclient/.gitignore@@ -0,0 +1,12 @@+# Binaries for programs and plugins+*.exe+*.exe~+*.dll+*.so+*.dylib++# Test binary, built with `go test -c`+*.test++# Output of the go coverage tool, specifically when used with LiteIDE+*.out\ No newline at end of filediff --git a/packages/goclient/go.mod b/packages/goclient/go.modnew file mode 100644index 0000000000..1dbec954cb--- /dev/null+++ b/packages/goclient/go.mod@@ -0,0 +1,7 @@+module github.com/remotion-dev/remotion/packages/go-client++go 1.19++require github.com/aws/aws-sdk-go v1.44.249++require github.com/jmespath/go-jmespath v0.4.0 // indirectdiff --git a/packages/goclient/go.sum b/packages/goclient/go.sumnew file mode 100644index 0000000000..a723ab5714--- /dev/null+++ b/packages/goclient/go.sum@@ -0,0 +1,38 @@+github.com/aws/aws-sdk-go v1.44.249 h1:UbUvh/oYHdAD3vZjNi316M0NIupJsrqAcJckVuhaCB8=+github.com/aws/aws-sdk-go v1.44.249/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=+github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=+github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=+github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=+github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=+golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=+golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=+golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=+golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=+golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=+golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=+golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=diff --git a/packages/goclient/goclient.go b/packages/goclient/goclient.gonew file mode 100644index 0000000000..3b407e419f--- /dev/null+++ b/packages/goclient/goclient.go@@ -0,0 +1,52 @@+package goclient++import (+ "encoding/json"+ "fmt"++ "github.com/aws/aws-sdk-go/aws"+ "github.com/aws/aws-sdk-go/aws/session"+ "github.com/aws/aws-sdk-go/service/lambda"+)++func invokeLambda(options *RemotionOptions) error {+ // Create a new AWS session+ sess := session.Must(session.NewSessionWithOptions(session.Options{+ SharedConfigState: session.SharedConfigEnable,+ }))++ // Create a new Lambda client+ svc := lambda.New(sess)++ // Create input for Lambda function+ payload, err := json.Marshal(options)+ if err != nil {+ return err+ }+ params := &lambda.InvokeInput{+ FunctionName: aws.String(options.FunctionName),+ Payload: payload,+ }++ // Invoke Lambda function+ resp, err := svc.Invoke(params)+ if err != nil {+ return err+ }++ // Handle response from Lambda function+ var output RemotionRenderResponse+ err = json.Unmarshal(resp.Payload, &output)+ if err != nil {+ return err+ }++ // Do something with the output from Lambda function+ fmt.Println(output)++ return nil+}++func Render(input *RemotionOptions) error {+ return invokeLambda(input)+}diff --git a/packages/goclient/models.go b/packages/goclient/models.gonew file mode 100644index 0000000000..e3a293061e--- /dev/null+++ b/packages/goclient/models.go@@ -0,0 +1,44 @@+package goclient++type RemotionOptions struct {+ ServeUrl string `json:"serveUrl"`+ FunctionName string `json:"functionName"`+ InputProps interface{} `json:"inputProps"`+ Composition string `json:"composition"`+ Type string `json:"type"`+ Codec string `json:"codec"`+ Version string `json:"version"`+ ImageFormat string `json:"imageFormat"`+ Crf int `json:"crf"`+ EnvVariables []interface{} `json:"envVariables"`+ Quality int `json:"quality"`+ MaxRetries int `json:"maxRetries"`+ Privacy string `json:"privacy"`+ LogLevel string `json:"logLevel"`+ FrameRange interface{} `json:"frameRange"`+ OutName interface{} `json:"outName"`+ TimeoutInMilliseconds int `json:"timeoutInMilliseconds"`+ ChromiumOptions []interface{} `json:"chromiumOptions"`+ Scale int `json:"scale"`+ EveryNthFrame int `json:"everyNthFrame"`+ NumberOfGifLoops int `json:"numberOfGifLoops"`+ ConcurrencyPerLambda int `json:"concurrencyPerLambda"`+ DownloadBehavior map[string]interface{} `json:"downloadBehavior"`+ Muted bool `json:"muted"`+ Overwrite bool `json:"overwrite"`+ AudioBitrate interface{} `json:"audioBitrate"`+ VideoBitrate interface{} `json:"videoBitrate"`+ Webhook interface{} `json:"webhook"`+ ForceHeight interface{} `json:"forceHeight"`+ ForceWidth interface{} `json:"forceWidth"`+ BucketName interface{} `json:"bucketName"`+ AudioCodec interface{} `json:"audioCodec"`+ ForceBucketName string `json:"forceBucketName"`+}++type RemotionRenderResponse struct {+ RenderId string `json:"renderId"`+ BucketName string `json:"bucketName"`+ CloudWatchLogs string `json:"cloudWatchLogs"`+ FolderInS3Console string `json:"folderInS3Console"`+}diff --git a/packages/goclient/utils.go b/packages/goclient/utils.gonew file mode 100644index 0000000000..649b7ca5d5--- /dev/null+++ b/packages/goclient/utils.go@@ -0,0 +1,55 @@+package goclient++import (+ "encoding/json"+ "errors"+ "fmt"+ "math/rand"+ "time"+)++func serializeInputProps(inputProps interface{}, region string, inputType string, userSpecifiedBucketName *string) (map[string]interface{}, error) {+ payload, err := json.Marshal(inputProps)+ if err != nil {+ return nil, errors.New("error serializing inputProps. Check it has no circular references or reduce the size if the object is big.")+ }++ // Set maximum inline payload size based on input type+ maxInlinePayloadSize := 200000+ if inputType == "still" {+ maxInlinePayloadSize = 5000000+ }++ // Check if payload size is within the limit+ if len(payload) > maxInlinePayloadSize {+ return nil, fmt.Errorf("warning: inputProps are over %dKB (%dKB) in size. This is not currently supported", maxInlinePayloadSize/1000, len(payload)/1024)+ }++ return map[string]interface{}{+ "type": "payload",+ "payload": string(payload),+ }, nil+}++func randomHash(options ...bool) string {+ var randomInTests bool+ if len(options) > 0 {+ randomInTests = options[0]+ }++ alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"+ length := 10++ if randomInTests {+ rand.Seed(1234)+ } else {+ rand.Seed(time.Now().UnixNano())+ }++ hash := make([]byte, length)+ for i := 0; i < length; i++ {+ hash[i] = alphabet[rand.Intn(len(alphabet))]+ }++ return string(hash)+}