Add more filters, options, make code more extendable#2
Conversation
* add filters: vflip, zoompan, hue, colorchannelmixer * add options for trim, overlay * filter code made more generic and extendable
|
Good point about |
There was a problem hiding this comment.
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.
|
|
||
| def _get_params_from_dict(self, d): | ||
| params = "" | ||
| for k in self.kwargs: |
| params += k + "={}:".format(self.kwargs[k]) | ||
| if len(params) > 0: | ||
| params = params[:-1] | ||
| return params |
There was a problem hiding this comment.
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.
| p = self._get_params_from_dict(d) | ||
| if len(p) > 0: | ||
| return self.NAME + "=" + p | ||
| return self.NAME |
There was a problem hiding this comment.
I think these could all be class methods, e.g.:
@classmethod
def _get_filter_from_dict(cls, d):
...
return cls.NAME
There was a problem hiding this comment.
How could that help though?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
These are gonna move to global functions anyways as part of the feature-1 branch, so no need to change anything
| self.kwargs = kwargs | ||
|
|
||
| def _get_filter(self): | ||
| return 'trim=start_frame={}:end_frame={},setpts={}'.format(self.start_frame, self.end_frame, self.setpts) |
There was a problem hiding this comment.
I guess this can be simplified when setpts becomes its own filter; then we can just use_get_filter_from_dict.
|
|
||
| def _get_filter(self): | ||
| return 'hflip' | ||
| return self.NAME |
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 putsetpts='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.