圣者
精华
|
战斗力 鹅
|
回帖 0
注册时间 2017-8-26
|
python脚本, 要装个ffmpeg
- import os
- import subprocess
- def get_video_duration(filename):
- """Get the duration of the video in seconds."""
- result = subprocess.run(
- ["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", filename],
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT
- )
- return float(result.stdout)
- def capture_screenshots(video_path, interval=15):
- """Capture screenshots from the video at the specified interval."""
- video_filename = os.path.basename(video_path)
- video_name, _ = os.path.splitext(video_filename)
- duration = get_video_duration(video_path)
-
- for t in range(0, int(duration), interval):
- time_str = f"{t:04d}"
- output_image = f"{video_name} - {time_str}.jpg"
- subprocess.run(["ffmpeg", "-ss", str(t), "-i", video_path, "-vframes", "1", "-q:v", "2", output_image])
- def process_videos_in_folder(folder_path, interval=15):
- """Process all videos in the specified folder."""
- for filename in os.listdir(folder_path):
- if filename.endswith((".mp4", ".mov", ".avi", ".mkv")):
- video_path = os.path.join(folder_path, filename)
- capture_screenshots(video_path, interval)
- # 设置你的视频文件夹路径
- video_folder = ""
- # 处理视频文件
- process_videos_in_folder(video_folder)
复制代码 |
评分
-
查看全部评分
|