Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- import subprocess
- from sys import argv, stderr
- def main():
- if len(argv) < 2 or "-help" in argv or "--help" in argv or "-h" in argv:
- displayHelp()
- return
- # find input file
- try:
- inputIndex = argv.index("-i")
- inputFile = argv[inputIndex + 1]
- except ValueError:
- print("Fatal: no input file given.", file=stderr)
- return
- # find the start parameter
- try:
- startIndex = argv.index("-ss")
- startTimestamp = argv[startIndex + 1]
- except ValueError:
- startTimestamp = "0"
- # find the t (length) parameter
- try:
- lengthIndex = argv.index("-t")
- lengthTimestamp = argv[lengthIndex + 1]
- except ValueError:
- lengthTimestamp = None
- # find the to parameter
- try:
- toIndex = argv.index("-to")
- toTimestamp = argv[toIndex + 1]
- except ValueError:
- toTimestamp = None
- # need the duration for size calculations
- if lengthTimestamp is None and toTimestamp is None:
- toEnd = True
- # find the length of the file
- command = ["ffprobe", "-i", inputFile, "-show_entries", "format=duration", "-v", "error",
- "-of", "csv=p=0"]
- result = subprocess.run(command, capture_output=True, check=True)
- duration = float(result.stdout) - float(startTimestamp)
- else:
- toEnd = False
- if lengthTimestamp is not None:
- duration = float(lengthTimestamp)
- else:
- duration = float(toTimestamp) - float(startTimestamp)
- outputFolder = not "-no_output_folder" in argv
- # find special filter flag
- # TODO: implement
- # build command
- command = ["ffmpeg", "-hide_banner", "-ss", startTimestamp]
- if not toEnd:
- if lengthTimestamp is not None:
- command.extend(["-t", lengthTimestamp])
- else:
- command.extend(["-to", toTimestamp])
- command.extend(["-i", inputFile, "-i", os.path.join("filters", "fortnite-filter.png"),
- "-/filter_complex", os.path.join("filters", "fortnite-filter-540.txt"),
- "-an", "-c:v", "libvpx-vp9", "-b:v", str(3.9 / duration) + "MiB",
- "-pass", "1", "-f", "null", os.devnull])
- subprocess.run(command, check=True)
- # remove the first pass stuff
- command = command[:-4]
- command.append("2")
- outputFile = inputFile[:inputFile.rfind(".")] + ".webm"
- if outputFolder:
- command.append(os.path.join("output", outputFile))
- else:
- command.append(outputFile)
- subprocess.run(command, check=True)
- def displayHelp():
- print("help")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment