MCPcopy Create free account
hub / github.com/astercloud/aster / NewVideoFromFile

Function NewVideoFromFile

pkg/media/types.go:158–186  ·  view source on GitHub ↗

NewVideoFromFile 从文件创建视频

(path string)

Source from the content-addressed store, hash-verified

156
157// NewVideoFromFile 从文件创建视频
158func NewVideoFromFile(path string) (*Video, error) {
159 data, err := os.ReadFile(path)
160 if err != nil {
161 return nil, fmt.Errorf("failed to read video file: %w", err)
162 }
163
164 video := &Video{
165 Name: filepath.Base(path),
166 Size: int64(len(data)),
167 Data: base64.StdEncoding.EncodeToString(data),
168 }
169
170 // 根据扩展名设置 MIME 类型
171 ext := strings.ToLower(filepath.Ext(path))
172 switch ext {
173 case ".mp4":
174 video.MimeType = "video/mp4"
175 case ".webm":
176 video.MimeType = "video/webm"
177 case ".mov":
178 video.MimeType = "video/quicktime"
179 case ".avi":
180 video.MimeType = "video/x-msvideo"
181 default:
182 video.MimeType = "video/*"
183 }
184
185 return video, nil
186}
187
188// Audio 音频
189type Audio struct {

Callers 1

NewVideoFunction · 0.85

Calls 1

ReadFileMethod · 0.45

Tested by

no test coverage detected