Spaces:
Sleeping
Sleeping
File size: 1,514 Bytes
d8fd28f a4af32a d8fd28f a4af32a d8fd28f a4af32a d8fd28f a4af32a d8fd28f a4af32a d8fd28f a4af32a d8fd28f a4af32a d8fd28f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# src/preprocessing/video_processor.py
import os
import subprocess
import logging
logger = logging.getLogger(__name__)
class VideoProcessor:
@staticmethod
def clean_directory(directory: str):
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
logger.error(f"Error deleting {file_path}: {e}")
@staticmethod
def convert_video_to_wav(video_file_path: str, wav_file_path: str) -> bool:
try:
if not os.path.exists(video_file_path):
logger.error(f"Video file does not exist: {video_file_path}")
return False
command = [
"ffmpeg",
"-i", video_file_path,
"-vn",
"-acodec", "pcm_s16le",
"-ar", "16000",
"-ac", "1",
"-y",
wav_file_path
]
result = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
if result.returncode != 0:
logger.error(f"FFmpeg error: {result.stderr}")
return False
return True
except Exception as e:
logger.error(f"Conversion error: {str(e)}")
return False |