Add video duration handling for chat rendering and merging
This commit is contained in:
parent
832bf4cf36
commit
cdef8cf9bb
4 changed files with 126 additions and 19 deletions
|
|
@ -98,6 +98,47 @@ def get_unique_filename(filepath: str) -> str:
|
|||
counter += 1
|
||||
|
||||
|
||||
def get_video_duration(video_path: str, ffmpeg_path: str) -> Optional[float]:
|
||||
"""
|
||||
Get the duration of a video file in seconds using FFmpeg.
|
||||
|
||||
Args:
|
||||
video_path: Path to the video file
|
||||
ffmpeg_path: Path to FFmpeg executable
|
||||
|
||||
Returns:
|
||||
float: Duration in seconds, or None if failed
|
||||
"""
|
||||
if not os.path.exists(video_path):
|
||||
return None
|
||||
|
||||
try:
|
||||
# Use ffprobe (comes with ffmpeg) to get duration
|
||||
ffprobe_path = ffmpeg_path.replace('ffmpeg', 'ffprobe')
|
||||
|
||||
cmd = [
|
||||
ffprobe_path,
|
||||
'-v', 'error',
|
||||
'-show_entries', 'format=duration',
|
||||
'-of', 'default=noprint_wrappers=1:nokey=1',
|
||||
video_path
|
||||
]
|
||||
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if result.returncode == 0 and result.stdout.strip():
|
||||
return float(result.stdout.strip())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def verify_streamlink() -> bool:
|
||||
"""
|
||||
Verify that streamlink is available.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue