-
Notifications
You must be signed in to change notification settings - Fork 0
/
crop_video.py
42 lines (30 loc) · 880 Bytes
/
crop_video.py
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
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 20 19:55:30 2018
Just a script to crop a video, since google did not help with that.
@author: Arsku
"""
import numpy as np
import cv2
INPUT_FILENAME = 'cat.mp4'
OUTPUT_FILENAME = 'cropped_cat.mp4'
SCALE_FACTOR = 0.5
OFFSETX = -50
OFFSETY = -50
WIDTH = 384
HEIGHT = 128
cap = cv2.VideoCapture(INPUT_FILENAME)
fourcc = cv2.VideoWriter_fourcc(*'MPEG')
out = cv2.VideoWriter(OUTPUT_FILENAME,fourcc, 20.0, (WIDTH,HEIGHT))
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
frame = cv2.resize(frame,(0,0), fx=SCALE_FACTOR, fy=SCALE_FACTOR, interpolation = cv2.INTER_CUBIC)
M = np.float32([[1,0,OFFSETX],[0,1,OFFSETY]])
dst = cv2.warpAffine(frame,M,(WIDTH,HEIGHT))
out.write(dst)
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()