To install this package:
go get github.com/opencoconut/coconutgo
First, we will setup the notification and storage settings:
package main
import (
"fmt"
"os"
"github.com/opencoconut/coconutgo"
)
func main() {
// Initialize the Client
cli := coconut.NewClient(coconut.Client{
APIKey: os.Getenv("COCONUT_API_KEY"),
Storage: coconut.Storage{
"service": "s3",
"region": "us-east-1",
"credentials": coconut.StorageCredentials{
"access_key_id": os.Getenv("AWS_ACCESS_KEY_ID"),
"secret_access_key": os.Getenv("AWS_SECRET_ACCESS_KEY"),
},
"bucket": "mybucket",
},
Notification: coconut.Notification{
"type": "http",
"url": "https://yoursite/api/coconut/webhook",
},
})
}
Creating complexe job is easy. In this example, we create 2 webp, 1 mp4 video and HLS outputs.
// Create a job
job, err := cli.Job.Create(coconut.JobCreate{
Input: coconut.InputCreate{
"url": "https://mysite/path/file.mp4",
},
Outputs: coconut.OutputCreate{
"webp:600x": coconut.OutputParams{
"key": "webp:cover",
"path": "/cover_%05d.webp",
"number": 10,
},
"webp:200x": coconut.OutputParams{
"key": "webp:thumbs",
"path": "/1080p.mp4",
"interval": 10,
"sprite": coconut.OutputParams{
"limit": 100,
"columns": 10,
},
"vtt": coconut.OutputParams{
"filename": "thumbs.vtt",
},
},
"mp4:::quality=4": coconut.OutputParams{
"key": "mp4",
"path": "/video.mp4",
},
"httpstream": coconut.OutputParams{
"hls": coconut.OutputParams{
"path": "hls/",
},
},
},
})
if err != nil {
fmt.Printf("%# v", err)
} else {
fmt.Printf("%# v", job)
}
job, err := cli.Job.Create(coconut.JobCreate{
Settings: coconut.Settings{
"ultrafast": true
},
Input: coconut.InputCreate{
"url": "https://mysite/path/file.mp4",
},
Outputs: coconut.OutputCreate{
"mp4:2160p": coconut.OutputParams{
"path": "/4k.mp4",
},
},
})