Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 기타
- Docker
- 오류
- Python
- 채보
- OpenCV
- label
- C
- C++
- C#
- Selenium
- LIST
- Visual Studio
- mysql
- VS Code
- 프로그래머스
- pytorch
- ubuntu
- pandas
- windows forms
- error
- 기타 연주
- Linux
- Numpy
- 명령어
- JSON
- paramiko
- SSH
- YOLO
- 핑거스타일
Archives
- Today
- Total
기계는 거짓말하지 않는다
Python 특정 프레임 수 이하 영상 데이터 삭제 본문
아래 예시는 실제 프레임 수가 15개 이하인 MP4 파일을 삭제한다.
opencv-python 라이브러리가 필요하며, 각 비디오 파일의 총 프레임 수를 확인하여 삭제한다.
import os
import glob
import cv2
import time
import datetime
# 디렉터리 경로 변경 필요
directory = '/path/directory'
count = 0
delete_count = 0
start_time = time.time()
mp4_files = glob.glob(os.path.join(directory, '*.mp4'))
for file in mp4_files:
try:
count += 1
# 비디오 파일 읽기
video = cv2.VideoCapture(file)
# 총 프레임 수 가져옴
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
video.release()
if total_frames <= 16:
os.remove(file)
print(f"{file} file deleted. frame count: {total_frames}")
delete_count += 1
print(f"delete count: {delete_count}")
if count % 10 == 0:
print(f"[{count} / {len(mp4_files)}] processing...")
except Exception as e:
print(f"{file} error: {e}")
total_time_str = str(datetime.timedelta(seconds=int(time.time() - start_time)))
print('\nTotal Time: {}'.format(total_time_str))
'Python' 카테고리의 다른 글
Python paramiko 프롬프트 상호작용 invoke_shell (0) | 2024.08.20 |
---|---|
Python logging 모듈 logger 설정(Settings) (0) | 2024.07.10 |
Python 모든 하위 디렉터리 파일 경로들을 디렉터리 별로 묶기 (1) | 2024.06.04 |
Python pip를 이용하여 설치된 패키지(package) 업그레이드(upgrade) (0) | 2024.06.04 |
Python 함수 주석 설명 추가 (0) | 2024.05.22 |
Comments