어도비프로 라이선스가 다되어서
다른 프로그램을 통해 동영상을 편집하게 되었는데
이 짜증나는 놈이 앞에 워터마크? 비슷한걸 강제로 박아넣는 문제가 생겨버렸다.
딱히 홍보할 생각은 없고
아무튼 저 로고가 3초간 강제 재생되어서
파이썬으로 저 부분을 편집해볼 생각이다.
우선 동영상을 읽어오자.
import sys
import cv2
cap = cv2.VideoCapture('Raw.mp4')
if not cap.isOpened():
print("Video open failed!")
sys.exit()
fps = cap.get(cv2.CAP_PROP_FPS)
print('FPS:', fps)
w = round(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
print('Frame width:', w)
h = round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print('Frame height:', h)
while True:
ret, frame = cap.read()
if not ret:
break
f = round(cap.get(cv2.CAP_PROP_POS_FRAMES))
print('Prop pos frames:', f)
cv2.imshow('frame', frame)
cv2.moveWindow('frame', 300, 100)
key = cv2.waitKey()
if key == 27:
break
if key == ord('b'):
cap.set(cv2.CAP_PROP_POS_FRAMES, f - 2)
cap.release()
cv2.destroyAllWindows()
cv2.waitkey()에 인자를 넣지 않아서 입력이 들어올때 까지 대기한다
키보드의 b('ㅠ')키를 누르면 cap.set()함수에 의해서 이전 프레임으로 돌아간다.
이 때, cap.read() 함수에 의해 다음 프레임이 불러와지므로
2를 빼주어서 이전 프레임을 보여주도록 했다.
이제 앞의 워터마크 영상이 몇 프레임까지인지를 확인해보자.
그러니까 116프레임까지를 없애면 된다.
cap = cv2.VideoCapture('Raw.mp4')
out = cv2.VideoWriter('Cut.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
cap.set(cv2.CAP_PROP_POS_FRAMES, 116)
while True:
ret, frame = cap.read()
if not ret:
break
out.write(frame)
cap.release()
out.release()
cv2.destroyAllWindows()
print('Edit Finished')
cv2.VideoWiter()에는 4가지 인자가 필요하다.
1. 파일이름
2. 코덱
3. fps
4. 크기
코덱에 관련해서는 다음 사이트를 참조바란다.
OpenCV: cv::VideoWriter Class Reference
OpenCV: cv::VideoWriter Class Reference
Video writer class. More... #include VideoWriter () Default constructors. More... VideoWriter (const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true) VideoWriter (const String &filename, int apiPreference, int four
docs.opencv.org
Video Codecs by FOURCC - fourcc.org
Video Codecs by FOURCC - fourcc.org
www.fourcc.org
조금 기다리니 출력창에 'Edit Finished' 문구가 떴다.
잘 생성되었나 살펴보자.
56초에서 52초로 길이가 줄어들었다.
참고로 영상은 다른 포스팅에서 확인할 수 있다.
EasyBoxer 제작기 1주차 (tistory.com)
EasyBoxer 제작기 1주차
포스팅을 어제 작성하는 도중에 사진의 정보가 노출되는 것을 확인하고 정보를 지우려고 편집을 시도했다. 그런데 어도비 프로 라이선스가 만료되어서 다른 영상 편집기로 편집을 진행했더니
tripleler.tistory.com
'CV(컴퓨터비전)' 카테고리의 다른 글
얼굴 비대칭 확인하기 (0) | 2022.05.23 |
---|---|
파이썬 사진 밝기 조절하기 (0) | 2022.04.11 |
Affine Transformation (0) | 2022.03.14 |
이미지 전단변환 (0) | 2022.03.06 |
이미지 회전하기 (0) | 2022.02.03 |
댓글