-
-
Save sujeong000/fea9bed87fec23b069b42677bffca620 to your computer and use it in GitHub Desktop.
바운딩 박스에 맞추어 영상 크롭
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
# 영상의 해상도를 구하는 함수 | |
def get_video_resolution(file_path): | |
vid = cv2.VideoCapture(file_path) | |
height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT) | |
width = vid.get(cv2.CAP_PROP_FRAME_WIDTH) | |
return ((width, height)) | |
# 입력, 출력 파일 경로 | |
input_file = "Fright to the Finish 1954-Scene-004.mp4" | |
output_file = "scene_stealer_004.mp4" | |
# 크롭 파라미터 계산 | |
WIDTH, HEIGHT = get_video_resolution(input_file) | |
x = xx * WIDTH | |
y = yy * HEIGHT | |
w = ww * WIDTH | |
h = hh * HEIGHT | |
# 영상을 크롭하는 ffmpeg 커멘드 생성 | |
command = ["ffmpeg", "-i", input_file, "-filter:v", f"crop={w}:{h}:{x}:{y}", "-c:a", "copy", output_file] | |
# 커멘드 실행 | |
subprocess.run(command) | |
def generate_thumbnail(input_video_path, output_image_path): | |
# 00:00:01초 지점에서 썸네일 이미지 생성 | |
subprocess.call(['/usr/bin/ffmpeg', '-i', input_video_path, '-ss', '00:00:01', '-vframes', '1', output_image_path]) | |
generate_thumbnail('scene_stealer_004.mp4', '004_scene_stealer_thumbnail.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment