feat: Replace pydub with ffmpeg for audio duration and metadata extraction in sound services
This commit is contained in:
@@ -7,7 +7,6 @@ import re
|
||||
from pathlib import Path
|
||||
|
||||
import ffmpeg
|
||||
from pydub import AudioSegment
|
||||
|
||||
from app.database import db
|
||||
from app.models.sound import Sound
|
||||
@@ -632,9 +631,17 @@ class SoundNormalizerService:
|
||||
# Calculate file hash
|
||||
file_hash = SoundNormalizerService._calculate_file_hash(file_path)
|
||||
|
||||
# Get duration using pydub
|
||||
audio = AudioSegment.from_wav(file_path)
|
||||
duration = len(audio) # Duration in milliseconds
|
||||
# Get duration using ffmpeg
|
||||
probe = ffmpeg.probe(file_path)
|
||||
audio_stream = next(
|
||||
(s for s in probe['streams'] if s['codec_type'] == 'audio'),
|
||||
None
|
||||
)
|
||||
|
||||
if audio_stream and 'duration' in audio_stream:
|
||||
duration = int(float(audio_stream['duration']) * 1000) # Convert to milliseconds
|
||||
else:
|
||||
duration = 0
|
||||
|
||||
return {
|
||||
"duration": duration,
|
||||
|
||||
Reference in New Issue
Block a user