feat(video): update ASR terminology and file type labels for improved clarity
- Changed 'Audio Processing' to 'Audio & Video' in English, Korean, Russian, and Chinese translations to reflect expanded functionality. - Updated ASR configuration titles and descriptions to include video processing capabilities, enhancing user understanding of the feature. - Renamed file type labels from 'Audio Files' to 'Audio & Video' across multiple languages for consistency and clarity. - Enhanced document upload handling in the KnowledgeBase to filter unsupported file types, providing user feedback for filtered images, videos, and audio files. This update improves the internationalization of the application and clarifies the capabilities of the ASR feature.
This commit is contained in:
@@ -15,6 +15,9 @@ type Extractor interface {
|
||||
// for each frame's image data. This is useful for streaming processing.
|
||||
ExtractFramesToReaders(ctx context.Context, videoBytes []byte, options *ExtractOptions) ([]io.Reader, error)
|
||||
|
||||
// ExtractAudio extracts the audio track from a video file and returns it as bytes.
|
||||
ExtractAudio(ctx context.Context, videoBytes []byte) ([]byte, error)
|
||||
|
||||
// GetVideoInfo retrieves basic information about a video file.
|
||||
// It returns a map containing duration, width, height, etc.
|
||||
GetVideoInfo(ctx context.Context, videoBytes []byte) (map[string]interface{}, error)
|
||||
|
||||
@@ -247,6 +247,50 @@ func (e *FFMpegExtractor) readExtractedFrames(ctx context.Context, frameDir stri
|
||||
return frames, nil
|
||||
}
|
||||
|
||||
// ExtractAudio extracts the audio track from a video using FFmpeg.
|
||||
func (e *FFMpegExtractor) ExtractAudio(ctx context.Context, videoBytes []byte) ([]byte, error) {
|
||||
tempVideoPath, err := e.writeTempVideo(videoBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.Remove(tempVideoPath)
|
||||
|
||||
tempAudioFile, err := os.CreateTemp(e.tempDir, "audio-output-*.mp3")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create temp audio file: %w", err)
|
||||
}
|
||||
tempAudioPath := tempAudioFile.Name()
|
||||
tempAudioFile.Close()
|
||||
defer os.Remove(tempAudioPath)
|
||||
|
||||
cmd := exec.CommandContext(ctx, e.ffmpegPath,
|
||||
"-i", tempVideoPath,
|
||||
"-vn",
|
||||
"-c:a", "libmp3lame",
|
||||
"-q:a", "2",
|
||||
"-y",
|
||||
tempAudioPath,
|
||||
)
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
if strings.Contains(stderr.String(), "Output file does not contain any stream") {
|
||||
logger.Infof(ctx, "[VideoFFMpeg] Video does not contain an audio stream")
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("ffmpeg audio extraction failed: %w, stderr: %s", err, stderr.String())
|
||||
}
|
||||
|
||||
audioBytes, err := os.ReadFile(tempAudioPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read extracted audio: %w", err)
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "[VideoFFMpeg] Extracted audio, size: %d bytes", len(audioBytes))
|
||||
return audioBytes, nil
|
||||
}
|
||||
|
||||
// GetVideoInfo returns basic information about a video.
|
||||
func (e *FFMpegExtractor) GetVideoInfo(ctx context.Context, videoBytes []byte) (map[string]interface{}, error) {
|
||||
tempVideoPath, err := e.writeTempVideo(videoBytes)
|
||||
|
||||
Reference in New Issue
Block a user