Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scaling #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions gifmaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,23 @@ def __init__(self, width, height, xpos, ypos):
self._xpos = xpos
self._ypos = ypos

def crop_argument(self, width, height, scale=None):
return ":".join(map(str, self._get_values(width, height, scale)))
@property
def height(self):
return self._height

def _get_values(self, width, height, scale):
@property
def width(self):
return self._width

def crop_argument(self, width, height):
return ":".join(map(str, self._get_values(width, height)))

def _get_values(self, width, height):
if self._percentages:
values = [self._width * width, self._height * height,
return [self._width * width, self._height * height,
self._xpos * width, self._ypos * height]
else:
values = [self._width, self._height, self._xpos, self._ypos]
if scale is not None:
values = [v * scale for v in values]
return values
return [self._width, self._height, self._xpos, self._ypos]

@classmethod
def from_arg(cls, arg):
Expand Down Expand Up @@ -123,12 +128,17 @@ def _extract_frames(video_data, output_dir, start=None, duration=None,
command += ['-t', str(duration)]
if crop is not None:
command += ['-vf', 'crop=%s' % crop.crop_argument(video_data.width,
video_data.height,
scale)]
if scale is not None:
scaled_height = int(round(video_data.height * scale))
scaled_width = int(round(video_data.width * scale))
command += ['-s', '%sx%s' % (scaled_width, scaled_height)]
video_data.height)]
height = crop.height
width = crop.width
else:
height = video_data.height
width = video_data.width

scale = 1 if scale is None else scale
scaled_height = int(round(height * scale))
scaled_width = int(round(width * scale))
command += ['-s', '%sx%s' % (scaled_width, scaled_height)]
command.append(os.path.join(output_dir, 'frames%05d.png'))
logging.info("Running command: %s", command)
subprocess.call(command)
Expand Down