|
|
|
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
|
|
def extract_keyframes(video_file_path):
|
|
"""
|
|
Extract keyframes from the given video file.
|
|
|
|
Parameters:
|
|
video_file_path (str): The path to the video file.
|
|
"""
|
|
|
|
base_name = os.path.splitext(os.path.basename(video_file_path))[0]
|
|
|
|
|
|
output_dir = os.path.join(os.path.dirname(video_file_path), base_name)
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
|
|
ffmpeg_command = [
|
|
'ffmpeg',
|
|
'-i', video_file_path,
|
|
'-vf', 'select=eq(pict_type\\,I)',
|
|
'-vsync', 'vfr',
|
|
os.path.join(output_dir, 'frame_%03d.png')
|
|
]
|
|
|
|
|
|
subprocess.run(ffmpeg_command, check=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python keyframe.py <path_to_video>")
|
|
sys.exit(1)
|
|
|
|
video_path = sys.argv[1]
|
|
extract_keyframes(video_path)
|
|
|