|
|
import os
|
|
|
import subprocess
|
|
|
|
|
|
def add_silence_to_audio_ffmpeg(audio_path, tmp_audio_path, silence_duration_s=0.5):
|
|
|
|
|
|
cmd = [
|
|
|
'ffmpeg',
|
|
|
'-i', audio_path,
|
|
|
'-f', 'lavfi',
|
|
|
'-t', str(silence_duration_s),
|
|
|
'-i', 'anullsrc=r=16000:cl=stereo',
|
|
|
'-filter_complex', '[1][0]concat=n=2:v=0:a=1[out]',
|
|
|
'-map', '[out]',
|
|
|
'-y', tmp_audio_path,
|
|
|
'-loglevel', 'error'
|
|
|
]
|
|
|
|
|
|
try:
|
|
|
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
raise RuntimeError(f"ffmpeg failed ({e.returncode}): {e.stderr.strip()}")
|
|
|
|
|
|
def convert_video_to_15fps_ffmpeg(video_path, output_path=None):
|
|
|
"""
|
|
|
Convert a video to 15 FPS using ffmpeg.
|
|
|
|
|
|
Parameters
|
|
|
----------
|
|
|
video_path : str
|
|
|
Path to the input .mp4 video.
|
|
|
output_path : str, optional
|
|
|
Path for the output video. If None, a new file will be created next to the input.
|
|
|
|
|
|
Returns
|
|
|
-------
|
|
|
str
|
|
|
The output video path.
|
|
|
"""
|
|
|
|
|
|
if not os.path.exists(video_path):
|
|
|
raise FileNotFoundError(f"Input video not found: {video_path}")
|
|
|
|
|
|
|
|
|
if output_path is None:
|
|
|
base, ext = os.path.splitext(video_path)
|
|
|
output_path = base + "_15fps.mp4"
|
|
|
|
|
|
cmd = [
|
|
|
"ffmpeg",
|
|
|
"-i", video_path,
|
|
|
"-filter:v", "fps=15",
|
|
|
"-c:a", "copy",
|
|
|
"-y", output_path,
|
|
|
"-loglevel", "error"
|
|
|
]
|
|
|
|
|
|
try:
|
|
|
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
raise RuntimeError(f"ffmpeg failed ({e.returncode}): {e.stderr.strip()}")
|
|
|
|
|
|
return output_path |