Skip to content

🎥 Make videos programmatically with React

initial woking code with that renders

Alex Fernandeza1e46cecbf3a
diff --git a/packages/goclient-example/main.go b/packages/goclient-example/main.go
index b7c99d1807..5e1d460afe 100644
--- a/packages/goclient-example/main.go
+++ b/packages/goclient-example/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"log"
"os"
@@ -19,14 +20,14 @@ func main() {
serveUrl := os.Getenv("REMOTION_APP_SERVER_URL")
functionName := os.Getenv("REMOTION_APP_FUNCTION_NAME")
region := os.Getenv("REMOTION_APP_REGION")
- bucketName := os.Getenv("REMOTION_APP_BUCKET")
- println(serveUrl)
input := &goclient.RemotionOptions{
- ServeUrl: serveUrl,
- FunctionName: functionName,
- Region: region,
- InputProps: nil,
+ ServeUrl: serveUrl,
+ FunctionName: functionName,
+ Region: region,
+ InputProps: map[string]interface{}{
+ "data": "Let's play",
+ },
Composition: "main",
Type: "start",
Codec: "h264",
@@ -40,9 +41,9 @@ func main() {
LogLevel: "info",
FrameRange: nil,
OutName: nil,
- TimeoutInMilliseconds: 0,
+ TimeoutInMilliseconds: 30000,
ChromiumOptions: []interface{}{},
- Scale: 0,
+ Scale: 1,
EveryNthFrame: 1,
NumberOfGifLoops: 0,
ConcurrencyPerLambda: 1,
@@ -58,10 +59,33 @@ func main() {
ForceWidth: nil,
BucketName: nil,
AudioCodec: nil,
- ForceBucketName: bucketName,
+ ForceBucketName: nil,
}
- _, error := goclient.Render(input)
+ response, error := goclient.RenderMedia(input)
+
if error != nil {
log.Fatal(err)
}
+
+ var bucketName string
+ var renderId string
+
+ output, ok := response.(map[string]interface{})
+ if !ok {
+
+ log.Fatal("%s %s", "invalid response format", err)
+ }
+
+ for key, value := range output {
+ switch key {
+ case "bucketName":
+ bucketName, _ = value.(string)
+ case "renderId":
+ renderId, _ = value.(string)
+
+ }
+ }
+
+ fmt.Printf("bucketName: %s\nRenderId: %s\n", bucketName, renderId)
+
}
diff --git a/packages/goclient/goclient.go b/packages/goclient/goclient.go
index a413612431..2ea1f1667b 100644
--- a/packages/goclient/goclient.go
+++ b/packages/goclient/goclient.go
@@ -9,7 +9,16 @@ import (
"github.com/aws/aws-sdk-go/service/lambda"
)
-func invokeLambda(options *RemotionOptions) (interface{}, error) {
+func parseLambdaResponse(response []byte) (map[string]interface{}, error) {
+ var output map[string]interface{}
+ err := json.Unmarshal(response, &output)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse Lambda response: %s", err)
+ }
+ return output, nil
+}
+
+func invokeLambda(options *RemotionOptions) (map[string]interface{}, error) {
// Create a new AWS session
sess := session.Must(session.NewSessionWithOptions(session.Options{
@@ -43,34 +52,19 @@ func invokeLambda(options *RemotionOptions) (interface{}, error) {
result, err := svc.Invoke(params)
if err != nil {
- println("Result error " + err.Error())
- return result, err
- }
-
- // Inspect the response
- if result.FunctionError != nil {
- println("Invoke Lambda FunctionError " + *result.FunctionError)
+ return nil, err
}
- // Get the actual response payload
- response := result.Payload
-
- fmt.Println("responseXXX")
- fmt.Println(response)
-
- // Handle response from Lambda function
- var output interface{}
- err = json.Unmarshal(response, &output)
+ // Unmarshal response from Lambda function
+ var output map[string]interface{}
+ err = json.Unmarshal(result.Payload, &output)
if err != nil {
return nil, err
}
- // Do something with the output from Lambda function
- fmt.Println(output)
-
- return nil, err
+ return output, nil
}
-func Render(input *RemotionOptions) (interface{}, error) {
+func RenderMedia(input *RemotionOptions) (interface{}, error) {
return invokeLambda(input)
}
diff --git a/packages/goclient/models.go b/packages/goclient/models.go
index 798cef9aae..67e6d741f9 100644
--- a/packages/goclient/models.go
+++ b/packages/goclient/models.go
@@ -34,18 +34,19 @@ type RemotionOptions struct {
ForceWidth interface{} `json:"forceWidth"`
BucketName interface{} `json:"bucketName"`
AudioCodec interface{} `json:"audioCodec"`
- ForceBucketName string `json:"forceBucketName"`
+ ForceBucketName *string `json:"forceBucketName"`
}
type internalOptions struct {
- serveUrl string
- inputProps interface{}
- composition string
- region string
- Type string
- Codec string
- Version string
- ImageFormat string
+ ServeUrl string `json:"serveUrl"`
+ FunctionName string `json:"functionName"`
+ Region string `json:"region"`
+ 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
EnvVariables []interface{}
Quality int
@@ -70,7 +71,7 @@ type internalOptions struct {
ForceWidth interface{} `json:"forceWidth"`
BucketName interface{} `json:"bucketName"`
AudioCodec interface{} `json:"audioCodec"`
- ForceBucketName string `json:"forceBucketName"`
+ ForceBucketName *string `json:"forceBucketName"`
}
type RemotionRenderResponse struct {
diff --git a/packages/goclient/utils.go b/packages/goclient/utils.go
index 20db96ec33..3e0ab9617c 100644
--- a/packages/goclient/utils.go
+++ b/packages/goclient/utils.go
@@ -10,7 +10,7 @@ import (
)
func serializeInputProps(inputProps interface{}, region string, inputType string,
- userSpecifiedBucketName string) (map[string]interface{}, error) {
+ 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.")
@@ -61,14 +61,16 @@ func constructInternals(options *RemotionOptions) internalOptions {
inputProps, err := serializeInputProps(options.InputProps, options.Region, "video-or-audio", options.ForceBucketName)
if err != nil {
- log.Fatal("Failed to open file:", err)
+ log.Fatal("Error in serializing input props", err)
}
+ // TODO validation errors
+
internalParams := &internalOptions{
- serveUrl: options.ServeUrl,
- inputProps: inputProps,
- composition: options.Composition,
- region: options.Region,
+ ServeUrl: options.ServeUrl,
+ InputProps: inputProps,
+ Composition: options.Composition,
+ Region: options.Region,
Type: options.Type,
Codec: options.Codec,
Version: options.Version,
@@ -102,3 +104,9 @@ func constructInternals(options *RemotionOptions) internalOptions {
return *internalParams
}
+
+func logInfo(message string) {
+ log.SetPrefix("INFO ")
+ log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
+ log.Println(message)
+}