Javanaut 8 months ago
parent 655833f13e
commit e52297b2ba

@ -598,16 +598,16 @@ def convert(ctx,
mediaFileProperties = FileProperties(context, sourcePath) mediaFileProperties = FileProperties(context, sourcePath)
if not cf is None: # if not cf is None:
#
cropArguments = mediaFileProperties.findCropArguments() cropArguments = {} if cf is None else mediaFileProperties.findCropArguments()
#
ctx.obj['logger'].info(f"\nSetting crop arguments: ouput width: {cropArguments[CropFilter.OUTPUT_WIDTH_KEY]} " # ctx.obj['logger'].info(f"\nSetting crop arguments: ouput width: {cropArguments[CropFilter.OUTPUT_WIDTH_KEY]} "
+ f"height: {cropArguments[CropFilter.OUTPUT_HEIGHT_KEY]} " # + f"height: {cropArguments[CropFilter.OUTPUT_HEIGHT_KEY]} "
+ f"offset x: {cropArguments[CropFilter.OFFSET_X_KEY]} " # + f"offset x: {cropArguments[CropFilter.OFFSET_X_KEY]} "
+ f"y: {cropArguments[CropFilter.OFFSET_Y_KEY]}") # + f"y: {cropArguments[CropFilter.OFFSET_Y_KEY]}")
#
cf.setArguments(**cropArguments) # cf.setArguments(**cropArguments)
ssc = ShiftedSeasonController(context) ssc = ShiftedSeasonController(context)
@ -798,7 +798,8 @@ def convert(ctx,
targetPath, targetPath,
targetFormat, targetFormat,
context['video_encoder'], context['video_encoder'],
chainIteration) chainIteration,
cropArguments)
endTime = time.perf_counter() endTime = time.perf_counter()
ctx.obj['logger'].info(f"\nDONE\nTime elapsed {endTime - startTime}") ctx.obj['logger'].info(f"\nDONE\nTime elapsed {endTime - startTime}")

@ -13,6 +13,7 @@ from ffx.constants import DEFAULT_cut_start, DEFAULT_cut_length
from ffx.filter.quality_filter import QualityFilter from ffx.filter.quality_filter import QualityFilter
from ffx.filter.preset_filter import PresetFilter from ffx.filter.preset_filter import PresetFilter
from ffx.filter.crop_filter import CropFilter
class FfxController(): class FfxController():
@ -176,7 +177,8 @@ class FfxController():
targetPath, targetPath,
targetFormat: str = '', targetFormat: str = '',
videoEncoder: VideoEncoder = VideoEncoder.VP9, videoEncoder: VideoEncoder = VideoEncoder.VP9,
chainIteration: list = []): chainIteration: list = [],
cropArguments: dict = {}):
# quality: int = DEFAULT_QUALITY, # quality: int = DEFAULT_QUALITY,
# preset: int = DEFAULT_AV1_PRESET): # preset: int = DEFAULT_AV1_PRESET):
@ -191,7 +193,17 @@ class FfxController():
filterParamTokens = [] filterParamTokens = []
filterParamTokens.extend(cropFilters[0]['tokens'] if cropFilters else [])
if cropArguments:
cropParams = (f"crop="
+ f"{CropFilter.OUTPUT_WIDTH_KEY}"
+ f":{CropFilter.OUTPUT_HEIGHT_KEY}"
+ f":{CropFilter.OFFSET_X_KEY}"
+ f":{CropFilter.OFFSET_Y_KEY}")
filterParamTokens.extend(cropParams)
filterParamTokens.extend(denoiseFilters[0]['tokens'] if denoiseFilters else []) filterParamTokens.extend(denoiseFilters[0]['tokens'] if denoiseFilters else [])
filterTokens = ['-vf', ', '.join(filterParamTokens)] filterTokens = ['-vf', ', '.join(filterParamTokens)]

@ -12,16 +12,6 @@ class CropFilter(Filter):
OFFSET_X_KEY = 'x_offset' OFFSET_X_KEY = 'x_offset'
OFFSET_Y_KEY = 'y_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): def __init__(self, **kwargs):
self.__outputWidth = int(kwargs.get(CropFilter.OUTPUT_WIDTH_KEY, 0)) self.__outputWidth = int(kwargs.get(CropFilter.OUTPUT_WIDTH_KEY, 0))
@ -39,8 +29,6 @@ class CropFilter(Filter):
def getPayload(self): def getPayload(self):
suffices = []
payload = {'identifier': CropFilter.IDENTIFIER, payload = {'identifier': CropFilter.IDENTIFIER,
'parameters': { 'parameters': {
CropFilter.OUTPUT_WIDTH_KEY: self.__outputWidth, CropFilter.OUTPUT_WIDTH_KEY: self.__outputWidth,
@ -51,10 +39,10 @@ class CropFilter(Filter):
'suffices': [], 'suffices': [],
'variant': f"C{self.__outputWidth}-{self.__outputHeight}-{self.__offsetX}-{self.__offsetY}", 'variant': f"C{self.__outputWidth}-{self.__outputHeight}-{self.__offsetX}-{self.__offsetY}",
'tokens': ['crop=' 'tokens': ['crop='
+ f"{self.__outputWidth}" + f"{self.__outputWidth}"
+ f":{self.__outputHeight}" + f":{self.__outputHeight}"
+ f":{self.__offsetX}" + f":{self.__offsetX}"
+ f":{self.__offsetY}"]} + f":{self.__offsetY}"]}
return payload return payload

Loading…
Cancel
Save