Exemple #1
0
 def handdleFrame(x: int):
     nonlocal toHanddle, handdledFrames, handdleVideoI
     sx = str(x)
     frame = toHanddle[sx]
     handdledFrame = paint.drawN(frame, w=w, h=h, blur=blur)
     handdledFrame = cv2.cvtColor(np.asarray(handdledFrame),
                                  cv2.COLOR_RGB2BGR)
     handdledFrames[sx] = handdledFrame
     for i in range(handdleVideoI, x + 1):
         si = str(i)
         if si in handdledFrames.keys():
             outVideo.write(handdledFrames[si])
             handdleVideoI += 1
         else:
             continue
     if toHanddle.__len__() <= 16:
         readOneGroup()
Exemple #2
0
def makeVideo(inputVideoPath: str,
              output: str,
              cutFrames: int = 1,
              w: int = 1,
              h: int = 1,
              blur: int = 0):
    """
    输出的视频没有音频轨道没有原视频对比,请放入其他剪辑软件中自行添加.另,如果w和h调的特别大的话,视频分辨率会超级高.
    :param input:输入视频的路径
    :param output:输出视频的路径,请以".avi"结尾
    :param cutFrames:抽帧频率,比如填1的话,则原视频每一帧都会处理后加入新视频中;填2的话,原视频每2帧会有一帧处理后加入新视频中
    :param w:横向画板数
    :param h:纵向画板数
    :param blur:控制线条加粗,设为0的话不做加粗处理.不为0的话只能填单数,即1,3,5,7等.某些情况下线条加粗比较符合像素风,请按需取用
    :return:None
    """
    inVideo = cv2.VideoCapture(inputVideoPath)
    inFps = inVideo.get(cv2.CAP_PROP_FPS)
    outFps = inFps / cutFrames
    framesCount = int(inVideo.get(cv2.CAP_PROP_FRAME_COUNT))

    outVideo = cv2.VideoWriter(
        output, cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), outFps,
        (37 * 20 * w + 278 + 262, 22 * 20 * h + 110 + 170))
    if (inVideo.isOpened() == False):
        print("Error opening video stream or file")
    i = 0
    while (inVideo.isOpened()):
        ret, frame = inVideo.read()
        if ret == True:
            if i % cutFrames == 0:
                try:
                    o = paint.drawN(frame, w=w, h=h, blur=blur)
                    img = cv2.cvtColor(np.asarray(o), cv2.COLOR_RGB2BGR)
                except:
                    pass
                else:
                    outVideo.write(img)
                print(f"{i:>10} of {framesCount} frames handdled")
            i += 1
        else:
            break
    inVideo.release()
    outVideo.release()
def mainFunc(args):
    import os

    if not os.path.exists(args.input):
        print("error: input file not found!")
        return

    if args.mode == None:
        fileTypeS = args.input.split(".")[-1]
        imageTypess = ("png", "jpg", "jpeg", "bmp")
        videoTypess = ("flv", "mp4", "avi", "mkv", "wma", "rmvb", "mov")
        fileTypeSLower = fileTypeS.lower()
        if fileTypeSLower in imageTypess:
            args.mode = "image"
        elif fileTypeSLower in videoTypess:
            args.mode = "video"
        else:
            print(
                "error: con't identify you input file mode,please appoint mode by -m argument"
            )

    if args.mode == "image":
        print(f"start draw image {args.input}......")
        import paint
        # if args.x is None:
        #     args.x = 1
        # if args.y is None:
        #     args.y = 1

        o = paint.drawN(imgPath=args.input,
                        w=args.width,
                        h=args.height,
                        blur=args.bold)
        if not args.output is None:
            oPath = args.output

        else:
            import time
            absInputPath = os.path.abspath(args.input)
            oPaths = os.path.split(absInputPath)
            rawFileName = oPaths[1]
            outFileName = f"{rawFileName.split('.')[0]}-{int(time.time())}.png"
            oPath = os.path.join(oPaths[0], outFileName)
            # oPath = f"azurlanePainting-{int(time.time())}.png"
        o.save(oPath, "PNG")
        print(f"image drawn completed -> {oPath}")
    elif args.mode == "video":
        print(f"start handdle video {args.input}......")
        import analyseVideo

        if not args.output is None:
            oPath = args.output

        else:
            import time

            absInputPath = os.path.abspath(args.input)
            oPaths = os.path.split(absInputPath)
            outFileName = f"{oPaths[1].split('.')[0]}-{int(time.time())}.avi"
            oPath = os.path.join(oPaths[0], outFileName)
            # import time
            #
            # oPath = f"azurlanePainting-{int(time.time())}.avi"

        analyseVideo.makeVideo(inputVideoPath=args.input,
                               output=oPath,
                               cutFrames=args.cutFrames,
                               w=args.width,
                               h=args.height,
                               blur=args.bold)
        print(f"video handdled completed -> {oPath}")
Exemple #4
0
 def handdleOne(frame):
     o = paint.drawN(frame, w=w, h=h, blur=blur)
     img = cv2.cvtColor(np.asarray(o), cv2.COLOR_RGB2BGR)
     pass