Skip to content

Commit

Permalink
add Linux paths support and weighting
Browse files Browse the repository at this point in the history
  • Loading branch information
couleurm committed Apr 23, 2022
1 parent 4baf137 commit 8dc6ce7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 21 deletions.
12 changes: 10 additions & 2 deletions blender.vpy
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,22 @@ if str(conf['misc']['deduplication']).lower() in yes:
video = filldrops.FillDrops(video, thresh=0.001)

if str(conf['frame blending']['enabled']).lower() in yes:

import weighting
repartition = conf['frame blending']['weighting']

frame_gap = int(video.fps / int(conf['frame blending']['fps']))
blended_frames = int(frame_gap * float(conf['frame blending']['intensity']))
if blended_frames > 0:
if blended_frames % 2 == 0: # If number is not odd (requires odd number of frames)
blended_frames += 1
weights = weighting.equal(blended_frames)
video = core.frameblender.FrameBlend(video, weights, True)

if ',' in repartition: # , means it's a list (aka array)
weights = repartition
elif type(repartition) is str:
weights = eval(f'weighting.{repartition}({blended_frames})')
verb(f"Weights: {weights}")
video = core.frameblender.FrameBlend(video, weights, True)
video = havsfunc.ChangeFPS(video, int(conf['frame blending']['fps']))

video.set_output()
5 changes: 5 additions & 0 deletions plugins/weighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def scaleWeights(frames):
def scaleRange(frames, a, b):
return [(x * (b - a) / (frames - 1)) + a for x in range(0, frames)]

def ascending(frames):
r = [*range(frames+1)] # Increments frames by 1
r = r[1:] # Skips first element
return r

def equal(frames):
return [1 / frames] * frames

Expand Down
95 changes: 76 additions & 19 deletions smoothie.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
from argparse import ArgumentParser
from sys import argv,exit
from os import path, system
from sys import argv, exit
from os import path, system#, getcwd
from configparser import ConfigParser
from subprocess import run
import subprocess
from subprocess import run, PIPE, Popen
from random import choice # Randomize smoothie's flavor
import platform # Get OS (detect win/linux)

if platform.architecture()[0] != '64bit':
print('This script is only compatible with 64bit systems.')
exit(1)

isLinux=platform.system() == 'Linux'
isWin=platform.system() == 'Windows'
if not isWin and not isLinux:
print(f'Unsupported OS "{platform.system()}"')
exit(1)

def pause(text):
none = input(text)

# Bool aliases
yes = ['True','true','yes','y','1']
Expand All @@ -23,15 +38,31 @@
args = parser.parse_args()

if args.dir:
run(f'explorer {path.dirname(argv[0])}')
exit(0)
scriptDir = path.dirname(__file__)
if isWin:
run(f'explorer {scriptDir}')
exit(0)
elif isLinux:
print(scriptDir)
exit(0)

if args.recipe:

recipe = path.abspath(path.join(path.dirname(__file__), "settings/recipe.ini"))

if path.exists(recipe) == False:
print("config path does not exist (are you messing with files?), exitting")
run('powershell -NoLogo')
run(f'explorer {recipe}')
exit(0)
print("config path does not exist (are you messing with files?), exitting..")
pause()
exit(1)

if isWin:
run(path.abspath(recipe), shell=True)
exit(0)
elif isLinux:
print('What code editor would you like to open your recipe with? (e.g nano, vim, code)')
print(f'This file is located at {recipe}')
editor = input('Editor:')
run(f'{path.abspath(editor)} {path.abspath(recipe)}', shell=True)


conf = ConfigParser()
Expand All @@ -56,7 +87,12 @@

for video in args.input: # Loops through every single video

# Title
if not args.verbose:
if isWin:
clear = 'cls'
elif isLinux:
clear = 'clear'
run(clear, shell = True)

round += 1

Expand All @@ -65,7 +101,8 @@
if len(args.input) > 1:
title = f'[{round}/{len(args.input)}] ' + title

system(f"title {title}")
if isWin:
system(f"title {title}")

# Suffix

Expand Down Expand Up @@ -105,8 +142,11 @@
count+=1

# VapourSynth
if isWin:
vspipe = path.join(path.dirname((path.dirname(__file__))),'VapourSynth','VSPipe.exe')

vspipe = path.join(path.dirname((path.dirname(__file__))),'VapourSynth','VSPipe.exe')
elif isLinux:
vspipe = 'vspipe'

if args.vpy:

Expand All @@ -119,10 +159,15 @@
vpy = path.abspath(path.join(path.dirname(__file__),'blender.vpy'))

command = [ # This is the master command, it gets appended some extra output args later down
f'{vspipe} -y "{vpy}" --arg input_video="{video}" --arg config_filepath="{config_filepath}" ',
f'- | {conf["encoding"]["process"]} -hide_banner -loglevel warning -stats -i - ',
f'{vspipe} -c y4m "{vpy}" --arg input_video="{path.abspath(video)}" --arg config_filepath="{config_filepath}" - ',
f'{conf["encoding"]["process"]} -hide_banner -loglevel warning -stats -i - ',
]

if isWin:
map = '-map 0:v -map 1:a?'
elif isLinux:
map = '-map 0:v -map 1:a\?'

if args.peek:
frame = int(args.peek[0]) # Extracting the frame passed from the singular array
command[0] += f'--start {frame} --end {frame}'
Expand All @@ -132,13 +177,25 @@
command[1] += f'{conf["encoding"]["args"]} "{out}"'
else:
# Adds as input the video to get it's audio tracks and gets encoding arguments from the config file
command[1] += f'-i "{path.abspath(video)}" -map 0:v -map 1:a? {conf["encoding"]["args"]} "{out}"'
command[1] += f'-i "{path.abspath(video)}" {map} {conf["encoding"]["args"]} "{out}"'

if args.verbose:
command[0] += ' --arg verbose=True'
for cmd in command: print(cmd)
for cmd in command: print(f"{cmd}\n")
print(f"Queuing video: {video}")

run(' '.join(command),shell=True)

system(f"title [{round}/{len(args.input)}] Smoothie - Finished! (EOF)")
#if run(' '.join(command),shell=True).returncode != 0:
# print(f"Something went wrong with {video}, press any key to un-pause")
# system('pause>nul')

#run(command[1], stdin = Popen(command[0], stdout = PIPE).stdout)
#ps = subprocess.Popen((command[0]), stdout=subprocess.PIPE)
#output = subprocess.check_output((command[1]), stdin=ps.stdout)
#ps.wait()
exitcode = run((command[0] + '|' + command[1]), shell=True).returncode
if exitcode != 0:
print(f"Something went wrong with {video}, press any key to un-pause")
if isWin: system('pause>nul')
exit

system(f"title [{round}/{len(args.input)}] Smoothie - Finished! (EOF)")

0 comments on commit 8dc6ce7

Please sign in to comment.