out = cv2.VideoWriter(path,fourcc ,frame_rate,(1200,600))

# ...

while cap.isOpend():
    ret, frame = cap.read()
    if not ret:
        break
    out_frame = model(frame) #딥러닝 모델을 통해서 나온 프레임 결과 shape = (500,500)
    out.write(out_frame)

위와 같이 영상을 불러온 다음에 각 프레임 별로 딥러닝 모델을 돌려서 얻어진 output으로 다시 영상을 제작하는 코드를 짜고 있었는데, 이상하게 만들어진 영상을 틀어보면 "재생할 수 없는 영상" 이라고 나오면서 재생이 안됨.

 

코드가 실행중에 에러가 나지도 않고 동영상 파일도 잘 나와있는데 이상하게 재생만 안됨.,,

 

대체 왜 이럴까 이래저래 열심히 뜯어보다 보니

VideoWriter에 입력되어 있는 shape은 (1200,600)

하지만, 내가 저장하려고 하는 out_frame의 shape은(500,500)

 

그렇다. 이 shape이 달라서 재생할 수 없는 영상이 계속 나온 것이었다.

 

그러면 에러라도 내주던가,, 왜 묵묵히 헛짓을 하는지 이해 할 수 없었다,,

 

out = cv2.VideoWriter(path,fourcc ,frame_rate,(1200,600))

# ...

while cap.isOpend():
    ret, frame = cap.read()
    if not ret:
        break
    out_frame = model(frame) #딥러닝 모델을 통해서 나온 프레임 결과 shape = (500,500)
    out_frame_reshape = cv2.resize(out_frame, dsize=(1200, 600), fx=0, fy=0) 
    
    out.write(out_frame_reshape)

위와 같이 shape을 맞춰주니 아주 잘 되었다.,