代码初始化
This commit is contained in:
@@ -13,10 +13,10 @@ import (
|
||||
)
|
||||
|
||||
// AudioExtractService 音频提取服务
|
||||
type AudioExtractService struct{}
|
||||
type audioExtractService struct{}
|
||||
|
||||
// AudioExtract 音频提取服务单例
|
||||
var AudioExtract = new(AudioExtractService)
|
||||
var AudioExtract = new(audioExtractService)
|
||||
|
||||
// ExtractAudioReq 提取音频请求
|
||||
type ExtractAudioReq struct {
|
||||
@@ -32,7 +32,7 @@ type ExtractAudioRes struct {
|
||||
}
|
||||
|
||||
// Extract 从视频中提取音频
|
||||
func (s *AudioExtractService) Extract(ctx context.Context, req *ExtractAudioReq) (res *ExtractAudioRes, err error) {
|
||||
func (s *audioExtractService) Extract(ctx context.Context, req *ExtractAudioReq) (res *ExtractAudioRes, err error) {
|
||||
// 1. 校验视频文件存在
|
||||
if _, err = os.Stat(req.VideoPath); os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("视频文件不存在: %s", req.VideoPath)
|
||||
@@ -117,7 +117,7 @@ func (s *AudioExtractService) Extract(ctx context.Context, req *ExtractAudioReq)
|
||||
}
|
||||
|
||||
// getFFmpegPath 获取 ffmpeg 可执行路径
|
||||
func (s *AudioExtractService) getFFmpegPath() (string, error) {
|
||||
func (s *audioExtractService) getFFmpegPath() (string, error) {
|
||||
// 1. 优先从配置读取
|
||||
ffmpegPath := g.Cfg().MustGet(context.Background(), "ffmpeg.path", "").String()
|
||||
if ffmpegPath != "" {
|
||||
@@ -135,7 +135,7 @@ func (s *AudioExtractService) getFFmpegPath() (string, error) {
|
||||
}
|
||||
|
||||
// getAudioDuration 获取音频时长
|
||||
func (s *AudioExtractService) getAudioDuration(ctx context.Context, ffmpegPath string, audioPath string) (string, error) {
|
||||
func (s *audioExtractService) getAudioDuration(ctx context.Context, ffmpegPath string, audioPath string) (string, error) {
|
||||
// 使用 ffprobe 获取时长
|
||||
// 先尝试查找 ffprobe
|
||||
ffprobePath := filepath.Join(filepath.Dir(ffmpegPath), "ffprobe")
|
||||
@@ -168,7 +168,7 @@ func (s *AudioExtractService) getAudioDuration(ctx context.Context, ffmpegPath s
|
||||
}
|
||||
|
||||
// ExtractAndCleanup 提取音频并清理临时视频文件
|
||||
func (s *AudioExtractService) ExtractAndCleanup(ctx context.Context, req *ExtractAudioReq) (res *ExtractAudioRes, err error) {
|
||||
func (s *audioExtractService) ExtractAndCleanup(ctx context.Context, req *ExtractAudioReq) (res *ExtractAudioRes, err error) {
|
||||
res, err = s.Extract(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user