Beispiel #1
0
def setupInfo(by, outputPath, root, commandIn, commandVideo, commandOut,
              slomos, sizes, start, width, height, frameRate, totalFrames,
              videoOnly):
    if root.total < 0 and totalFrames > 0:
        root.total = totalFrames - start
    if frameRate:
        for opt in slomos:
            frameRate *= opt['sf']
    outWidth, outHeight = (width, height)
    for opt in sizes:
        if opt['op'] == 'SR':
            outWidth *= opt['scale']
            outHeight *= opt['scale']
        else:  # resize
            outWidth = round(
                outWidth * opt['scaleW']) if 'scaleW' in opt else opt['width']
            outHeight = round(
                outHeight *
                opt['scaleH']) if 'scaleH' in opt else opt['height']
    commandVideo[8] = f'{outWidth}x{outHeight}'
    commandVideo[10] = str(frameRate)
    videoOnly |= start > 0
    if videoOnly or by:
        commandVideo = commandVideoSkip(commandVideo)
    if videoOnly or not by:
        commandVideo[-1] = outputPath
        i = commandIn.index('-vn')
        commandIn = clipList(commandIn, i, i + 5)
        commandOut = None
    root.multipleLoad(width * height * 3)
    initialETA(root)
    root.reset().trace(0)
    return commandIn, commandVideo, commandOut
Beispiel #2
0
def run(cases, times=1):
    for _, node, _1 in cases:
        node.learn = times
        ops[node.op] = newOp(slideAverage(1 - 1 / times))
    for i in range(times):
        for process, node, _ in cases:
            initialETA(node)
            process(inTensor)
            torch.cuda.empty_cache()
Beispiel #3
0
def begin(root, nodes=[], setAllCallback=True):
  context.root = root
  root.nodes = []
  for n in nodes:
    root.append(n)
  if setAllCallback:
    if not setAllCallback < 0:
      setCallback(root, onProgress, True)
  else:
    root.setCallback(onProgress)
  initialETA(root)
  return root
Beispiel #4
0
def prepare(video, steps):
  optEncode = steps[-1]
  encodec = optEncode['codec'] if 'codec' in optEncode else config.defaultEncodec  # pylint: disable=E1101
  optDecode = steps[0]
  decodec = optDecode['codec'] if 'codec' in optDecode else config.defaultDecodec  # pylint: disable=E1101
  optRange = steps[1]
  start = int(optRange['start']) if 'start' in optRange else 0
  outDir = config.outDir  # pylint: disable=E1101
  procSteps = stepVideo + list(steps[2:-1])
  process, nodes = genProcess(procSteps)
  root = begin(Node({'op': 'video', 'encodec': encodec}, 1, 2, 0), nodes, False)
  context.root = root
  width, height, frameRate, totalFrames = getVideoInfo(video)
  slomos = [*filter((lambda opt: opt['op'] == 'slomo'), procSteps)]
  if 'frameRate' in optEncode:
    frameRate = optEncode['frameRate']
  else:
    for opt in slomos:
      frameRate *= opt['sf']
  if 'width' in optDecode:
    width = optDecode['width']
  if 'height' in optDecode:
    height = optDecode['height']
  outWidth, outHeight = (width, height)
  for opt in filter((lambda opt: opt['op'] == 'SR' or opt['op'] == 'resize'), procSteps):
    if opt['op'] == 'SR':
      outWidth *= opt['scale']
      outHeight *= opt['scale']
    else: # resize
      outWidth = round(outWidth * opt['scaleW']) if 'scaleW' in opt else opt['width']
      outHeight = round(outHeight * opt['scaleH']) if 'scaleH' in opt else opt['height']
  if start < 0:
    start = 0
  if start and len(slomos): # should generate intermediate frames between start-1 and start
    start -= 1
    for opt in slomos:
      opt['opt'].firstTime = 0
  stop = None
  if 'stop' in optRange:
    stop = int(optRange['stop'])
    if stop <= start:
      stop = None
  root.total = (stop if stop else totalFrames) - start
  if not stop:
    stop = 0xffffffff
  root.multipleLoad(width * height * 3)
  initialETA(root)
  root.reset().trace(0)
  videoName = config.getPath()
  outputPath = outDir + '/' + videoName
  commandIn = [
    ffmpegPath,
    '-i', video,
    '-an',
    '-sn',
    '-f', 'rawvideo',
    '-s', '{}x{}'.format(width, height),
    '-pix_fmt', pix_fmt]
  if len(decodec):
    commandIn.extend(decodec.split(' '))
  commandIn.append('-')
  commandOut = [
    ffmpegPath,
    '-y',
    '-f', 'rawvideo',
    '-pix_fmt', pix_fmt,
    '-s', '{}x{}'.format(outWidth, outHeight),
    '-r', str(frameRate),
    '-i', '-',
    '-i', video,
    '-map', '0:v',
    '-map', '1?',
    '-map', '-1:v',
    '-c:1', 'copy',
    '-c:v:0']
  if start > 0:
    commandOut = commandOut[:12] + commandOut[22:]
  if len(encodec):
    commandOut.extend(encodec.split(' '))
  commandOut.append(outputPath)
  return commandIn, commandOut, outputPath, width, height, start, stop, root, process