You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Video Processing
Video Frame Extraction (Go SDK)
Copy page
Download PDF
Video Frame Extraction (Go SDK)
The video frame capture function enables extraction of a single frame from a video stream at a specified time and resizes it to a designated image size. This article describes how to perform video frame extraction using the TOS Go SDK.​
Sample Code​
The following code demonstrates how to extract the video frame at 300 milliseconds, save the captured image as temp.jpg, and download it to the local device.​
​
package main​
​
import (​
"context"​
"fmt"​
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"​
)​
​
func checkErr(err error) {​
if err != nil {​
if serverErr, ok := err.(*tos.TosServerError); ok {​
fmt.Println("Error:", serverErr.Error())​
fmt.Println("Request ID:", serverErr.RequestID)​
fmt.Println("Response Status Code:", serverErr.StatusCode)​
fmt.Println("Response Header:", serverErr.Header)​
fmt.Println("Response Err Code:", serverErr.Code)​
fmt.Println("Response Err Msg:", serverErr.Message)​
} else {​
fmt.Println("Error:", err)​
}​
panic(err)​
}​
}​
​
func main() {​
var (​
accessKey = os.Getenv("TOS_ACCESS_KEY")​
secretKey = os.Getenv("TOS_SECRET_KEY")​
​
endpoint = "https://tos-cn-beijing.volces.com"​
region = "cn-beijing"​
​
bucketName = "*** Provide your bucket name ***"​
​
​
videoKey = "video.mp4"​
ctx = context.Background()​
​
fileName = "temp.jpg"​
)​
​
client, err := tos.NewClientV2(endpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)))​
checkErr(err)​
​
​
style := "video/snapshot,t_300" ​
​
_, err = client.GetObjectToFile(ctx, &tos.GetObjectToFileInput{GetObjectV2Input: tos.GetObjectV2Input{Bucket: bucketName, Key: videoKey, Process: style}, FilePath: fileName})​
checkErr(err)​
​
}​
​
Relevant Documentation​
For a detailed introduction to video frame extraction, please refer to Video Frame Extraction.​
Last updated: 2025.09.19 17:30:23