Skip to content

Add more filters, options, make code more extendable#2

Merged
kkroening merged 1 commit into
kkroening:masterfrom
depau-forks:patch-1
May 26, 2017
Merged

Add more filters, options, make code more extendable#2
kkroening merged 1 commit into
kkroening:masterfrom
depau-forks:patch-1

Conversation

@depau

@depau depau commented May 25, 2017

Copy link
Copy Markdown
Collaborator
  • add filters: vflip, zoompan, hue, colorchannelmixer
  • add options for trim, overlay
  • filter code made more generic and extendable

The last one has been done by adding some helper methods to base filter class, which are called in child classes as needed. I tried not to break API but I did break it for trim, in which you put setpts='PTS-STARTPTS' by default. That can be done as a separate filter, though I didn't: I kept the "setpts" keyword argument, just in case.

* add filters: vflip, zoompan, hue, colorchannelmixer
* add options for trim, overlay
* filter code made more generic and extendable
@kkroening

Copy link
Copy Markdown
Owner

Good point about setpts='PTS-STARTPTS' That should almost certainly be its own filter. I'll do that in another PR

@kkroening kkroening left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Some minor comments, but should be okay as is.

I like the approach of storing filter parameters as self.kwargs - it makes things more general purpose and probably easier to maintain.

I'd say let's merge it and I'll make a few tweaks to it as I refactor and add pydocs.

Comment thread ffmpeg/__init__.py

def _get_params_from_dict(self, d):
params = ""
for k in self.kwargs:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be for k in d?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Whoops!

Comment thread ffmpeg/__init__.py
params += k + "={}:".format(self.kwargs[k])
if len(params) > 0:
params = params[:-1]
return params

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this could be condensed:

return ':'.join(['{}={}'.format(k, v) for k, v in d.items()])

Not a big deal though - it's okay the way it is, aside from the for k in d thing mentioned above.

Comment thread ffmpeg/__init__.py
p = self._get_params_from_dict(d)
if len(p) > 0:
return self.NAME + "=" + p
return self.NAME

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these could all be class methods, e.g.:

@classmethod
def _get_filter_from_dict(cls, d):
    ...
    return cls.NAME

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could that help though?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tends to be more obvious (IMO) that you're not mutating variables on self. Not a big deal - more of just a small code organizational thing

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are gonna move to global functions anyways as part of the feature-1 branch, so no need to change anything

Comment thread ffmpeg/__init__.py
self.kwargs = kwargs

def _get_filter(self):
return 'trim=start_frame={}:end_frame={},setpts={}'.format(self.start_frame, self.end_frame, self.setpts)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this can be simplified when setpts becomes its own filter; then we can just use_get_filter_from_dict.

Comment thread ffmpeg/__init__.py

def _get_filter(self):
return 'hflip'
return self.NAME

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@kkroening kkroening merged commit dae788b into kkroening:master May 26, 2017
@depau depau deleted the patch-1 branch May 28, 2017 18:46
@depau depau restored the patch-1 branch December 12, 2017 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants