Skip to content

Commit

Permalink
A few video rendering tweaks, including better handling when a display
Browse files Browse the repository at this point in the history
resolution is specified in the metadata.
  • Loading branch information
clolsonus committed Dec 29, 2020
1 parent 68d996d commit 5800959
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 7 additions & 8 deletions lib/video_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
def get_fit(frame, scale_w, scale_h):
if scale_w < scale_h:
result = cv2.resize(frame, None, fx=scale_w, fy=scale_w,
interpolation=cv2.INTER_CUBIC)
interpolation=cv2.INTER_AREA)
else:
result = cv2.resize(frame, None, fx=scale_h, fy=scale_h,
interpolation=cv2.INTER_CUBIC)
interpolation=cv2.INTER_AREA)
return result

# return a scaled version of the frame that stretches vertically and
# is cropped (if needed) horizontally
def get_fit_height(frame, scale_h):
result = cv2.resize(frame, None, fx=scale_h, fy=scale_h,
interpolation=cv2.INTER_CUBIC)
interpolation=cv2.INTER_AREA)
return result

def get_zoom(frame, scale_w, scale_h):
if scale_w < scale_h:
result = cv2.resize(frame, None, fx=scale_h, fy=scale_h,
interpolation=cv2.INTER_CUBIC)
interpolation=cv2.INTER_AREA)
else:
result = cv2.resize(frame, None, fx=scale_w, fy=scale_w,
interpolation=cv2.INTER_CUBIC)
interpolation=cv2.INTER_AREA)
return result

def clip_frame(frame, cell_w, cell_h):
Expand Down Expand Up @@ -56,18 +56,17 @@ def fit_face(v):
if v.face.count > 0 and not v.local_time is None:
(l, r, t, b) = v.face.get_face(v.local_time, 1.0)
else:
(b, r) = v.raw_frame.shape[:2]
l = 0
r = framew
t = 0
b = frameh
face_area = (r - l) * (b - t)
cell_area = v.size_w * v.size_h
if face_area < 2 * cell_area:
# try something crazy (subpixel cropping by scaling up and
# then back down)
scale = 2.0
superscale = cv2.resize(v.raw_frame, None, fx=scale, fy=scale,
interpolation=cv2.INTER_CUBIC)
interpolation=cv2.INTER_AREA)
l = l * scale
r = r * scale
t = t * scale
Expand Down
9 changes: 6 additions & 3 deletions lib/video_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ def open(self, file):
self.w = int(metadata['video']['@width'])
self.h = int(metadata['video']['@height'])
if '@sample_aspect_ratio' in metadata['video']:
dw, _ = metadata['video']['@sample_aspect_ratio'].split(':')
if int(dw) > self.w:
self.displayw = int(dw)
num, den = metadata['video']['@sample_aspect_ratio'].split(':')
if int(den) > 0:
width_mul = int(num) / int(den)
else:
width_mul = 1
self.displayw = int(round(self.w * width_mul))
self.w = self.displayw
if '@duration' in metadata['video']:
self.duration = float(metadata['video']['@duration'])
Expand Down

0 comments on commit 5800959

Please sign in to comment.