From 47baf87da3dfa34f855be04e754b5a15bd8a6b22 Mon Sep 17 00:00:00 2001 From: hypox64 Date: Fri, 12 Jun 2020 20:27:23 +0800 Subject: [PATCH] Support Windows --- img2shell.py | 2 +- options.py | 2 +- play.py | 52 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/img2shell.py b/img2shell.py index 1f9068c..9b94568 100644 --- a/img2shell.py +++ b/img2shell.py @@ -102,7 +102,7 @@ class Transformer(object): def pixel_color(self,Y,dis): - if Y<24: + if Y<32: return ' ' # color diff --git a/options.py b/options.py index 6433c33..7527628 100644 --- a/options.py +++ b/options.py @@ -9,7 +9,7 @@ class Options(): self.parser.add_argument('-m','--media', type=str, default='./imgs/test.jpg',help='your video or image path') self.parser.add_argument('-g','--gray', action='store_true', help='if specified, play gray video') self.parser.add_argument('-f','--fps', type=int, default=0,help='playing fps, 0-> auto') - self.parser.add_argument('-c','--charstyle', type=int, default=3,help='style of output') + self.parser.add_argument('-c','--charstyle', type=int, default=1,help='style of output') self.parser.add_argument('-s','--screen', type=int, default=1,help='size of shell 1:80*24 2:132*43 3:203*55') self.parser.add_argument('--ori_fps', type=int, default=0,help='original fps for video, 0-> auto') diff --git a/play.py b/play.py index 0773877..8f1cd76 100644 --- a/play.py +++ b/play.py @@ -1,11 +1,13 @@ import os import sys import time +import multiprocessing from multiprocessing import Process, Queue import threading import subprocess import numpy as np import cv2 +import platform from util import util,ffmpeg from img2shell import Transformer @@ -30,6 +32,9 @@ def timer(opt,timerQueueime): timerQueueime.put(True) opt = Options().getparse() +system_type = 'Linux' +if 'Windows' in platform.platform(): + system_type = 'Windows' #-------------------------------Media Init------------------------------- if util.is_img(opt.media): @@ -41,7 +46,7 @@ elif util.is_video(opt.media): opt.frame_num = int(endtime*fps-5) if opt.ori_fps == 0: opt.ori_fps = fps - util.clean_tempfiles(tmp_init=True) + util.makedirs('./tmp') else: print('Can not load this file!') @@ -68,29 +73,34 @@ if util.is_video(opt.media): opt.fps = np.clip(recommend_fps,1,opt.ori_fps) else: opt.fps = np.clip(opt.fps,1,opt.ori_fps) - ffmpeg.video2voice(opt.media,'-ar 16000 ./tmp/tmp.wav') + if system_type == 'Linux': + ffmpeg.video2voice(opt.media,'-ar 16000 ./tmp/tmp.wav') #-------------------------------main------------------------------- -if util.is_img(opt.media): - print(transformer.convert(img,opt.gray)) -elif util.is_video(opt.media): - imgQueue = Queue(1) - timerQueue = Queue() +if __name__ == '__main__': + if system_type == 'Windows': + multiprocessing.freeze_support() + if util.is_img(opt.media): + print(transformer.convert(img,opt.gray)) + elif util.is_video(opt.media): + imgQueue = Queue(1) + timerQueue = Queue() - imgload_p = Process(target=readvideo,args=(opt,imgQueue)) - imgload_p.daemon = True - imgload_p.start() + imgload_p = Process(target=readvideo,args=(opt,imgQueue)) + imgload_p.daemon = True + imgload_p.start() - timer_p = Process(target=timer,args=(opt,timerQueue)) - timer_p.daemon = True - timer_p.start() + timer_p = Process(target=timer,args=(opt,timerQueue)) + timer_p.daemon = True + timer_p.start() - time.sleep(0.5) - subprocess.Popen('paplay ./tmp/tmp.wav', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + time.sleep(0.5) + if system_type == 'Linux': + subprocess.Popen('paplay ./tmp/tmp.wav', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - for i in range(int(opt.frame_num*opt.fps/opt.ori_fps)-1): - timerQueue.get() - img = imgQueue.get() - string = transformer.convert(img,opt.gray) - t=threading.Thread(target=print,args=(string,)) - t.start() + for i in range(int(opt.frame_num*opt.fps/opt.ori_fps)-1): + timerQueue.get() + img = imgQueue.get() + string = transformer.convert(img,opt.gray) + t=threading.Thread(target=print,args=(string,)) + t.start() -- GitLab