tf auto_crop
parent
48841c5750
commit
e1395aeca0
@ -0,0 +1,67 @@
|
||||
import itertools
|
||||
|
||||
from .filter import Filter
|
||||
|
||||
|
||||
class CropFilter(Filter):
|
||||
|
||||
IDENTIFIER = 'crop'
|
||||
|
||||
OUTPUT_WIDTH_KEY = 'output_width'
|
||||
OUTPUT_HEIGHT_KEY = 'output_height'
|
||||
OFFSET_X_KEY = 'x_offset'
|
||||
OFFSET_Y_KEY = 'y_offset'
|
||||
|
||||
# ffmpeg -i in.mp4 -vf "crop=out_w:out_h:x:y" out.mp4
|
||||
#
|
||||
# Where the options are as follows:
|
||||
#
|
||||
# use "-vf" or -"filter:v" - depending on your version of ffmpeg/avconv
|
||||
# out_w is the width of the output rectangle
|
||||
# out_h is the height of the output rectangle
|
||||
# x and y specify the top left corner of the output rectangle (coordinates start at (0,0) in the top left corner of the input)
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
self.__outputWidth = int(kwargs.get(CropFilter.OUTPUT_WIDTH_KEY))
|
||||
self.__outputHeight = int(kwargs.get(CropFilter.OUTPUT_HEIGHT_KEY))
|
||||
self.__offsetX = int(kwargs.get(CropFilter.OFFSET_X_KEY))
|
||||
self.__offsetY = int(kwargs.get(CropFilter.OFFSET_Y_KEY))
|
||||
|
||||
super().__init__(self)
|
||||
|
||||
def setArguments(self,
|
||||
outputWidth: int,
|
||||
outputHeight: int,
|
||||
offsetX: int,
|
||||
offsetY: int):
|
||||
self.__outputWidth = int(outputWidth)
|
||||
self.__outputHeight = int(outputHeight)
|
||||
self.__offsetX = int(offsetX)
|
||||
self.__offsetY = int(offsetY)
|
||||
|
||||
def getPayload(self):
|
||||
|
||||
suffices = []
|
||||
|
||||
payload = {'identifier': CropFilter.IDENTIFIER,
|
||||
'parameters': {
|
||||
CropFilter.OUTPUT_WIDTH_KEY: self.__outputWidth,
|
||||
CropFilter.OUTPUT_HEIGHT_KEY: self.__outputHeight,
|
||||
CropFilter.OFFSET_X_KEY: self.__offsetX,
|
||||
CropFilter.OFFSET_Y_KEY: self.__offsetY
|
||||
},
|
||||
'suffices': [],
|
||||
'variant': f"C{self.__outputWidth}-{self.__outputHeight}-{self.__offsetX}-{self.__offsetY}",
|
||||
'tokens': ['crop='
|
||||
+ f"{self.__outputWidth}"
|
||||
+ f":{self.__outputHeight}"
|
||||
+ f":{self.__offsetX}"
|
||||
+ f":{self.__offsetY}"]}
|
||||
|
||||
return payload
|
||||
|
||||
|
||||
def getYield(self):
|
||||
yield self.getPayload()
|
Loading…
Reference in New Issue