Python : Cv2를 이용하여 비디오를 프레임 단위로 분해 - escaco95/Charcoal GitHub Wiki

2019.09.25 (3.6.8)

import cv2
import os
import sys

def run(videoFilePath,outputDirectoryPath):
    os.chdir(outputDirectoryPath)
    print('Source Video : '+videoFilePath)
    print('Output Dir : '+outputDirectoryPath)
    cap = cv2.VideoCapture(videoFilePath)
    frameNumber = 0
    while (cap.isOpened()):
        ret, frame = cap.read()
        if ret is True:
            framePath = outputDirectoryPath +'\\'+ str(frameNumber) + '.jpg'
            if os.path.isfile(framePath) is False:
                cv2.imwrite(framePath, frame)
            frameNumber += 1
            print('<CMDOUTPUT> PROGRESS '+str(frameNumber))
        else:
            break
    cap.release()
    
# CMD 인자를 넘겨받아 실행
videoFilePath = str(sys.argv[1])
outputDirectoryPath = str(sys.argv[2])
run(videoFilePath,outputDirectoryPath)

# Quit
quit()
⚠️ **GitHub.com Fallback** ⚠️