提交 47baf87d 编写于 作者: H hypox64

Support Windows

上级 15359ca7
...@@ -102,7 +102,7 @@ class Transformer(object): ...@@ -102,7 +102,7 @@ class Transformer(object):
def pixel_color(self,Y,dis): def pixel_color(self,Y,dis):
if Y<24: if Y<32:
return ' ' return ' '
# color # color
......
...@@ -9,7 +9,7 @@ class Options(): ...@@ -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('-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('-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('-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('-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') self.parser.add_argument('--ori_fps', type=int, default=0,help='original fps for video, 0-> auto')
......
import os import os
import sys import sys
import time import time
import multiprocessing
from multiprocessing import Process, Queue from multiprocessing import Process, Queue
import threading import threading
import subprocess import subprocess
import numpy as np import numpy as np
import cv2 import cv2
import platform
from util import util,ffmpeg from util import util,ffmpeg
from img2shell import Transformer from img2shell import Transformer
...@@ -30,6 +32,9 @@ def timer(opt,timerQueueime): ...@@ -30,6 +32,9 @@ def timer(opt,timerQueueime):
timerQueueime.put(True) timerQueueime.put(True)
opt = Options().getparse() opt = Options().getparse()
system_type = 'Linux'
if 'Windows' in platform.platform():
system_type = 'Windows'
#-------------------------------Media Init------------------------------- #-------------------------------Media Init-------------------------------
if util.is_img(opt.media): if util.is_img(opt.media):
...@@ -41,7 +46,7 @@ elif util.is_video(opt.media): ...@@ -41,7 +46,7 @@ elif util.is_video(opt.media):
opt.frame_num = int(endtime*fps-5) opt.frame_num = int(endtime*fps-5)
if opt.ori_fps == 0: if opt.ori_fps == 0:
opt.ori_fps = fps opt.ori_fps = fps
util.clean_tempfiles(tmp_init=True) util.makedirs('./tmp')
else: else:
print('Can not load this file!') print('Can not load this file!')
...@@ -68,29 +73,34 @@ if util.is_video(opt.media): ...@@ -68,29 +73,34 @@ if util.is_video(opt.media):
opt.fps = np.clip(recommend_fps,1,opt.ori_fps) opt.fps = np.clip(recommend_fps,1,opt.ori_fps)
else: else:
opt.fps = np.clip(opt.fps,1,opt.ori_fps) 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------------------------------- #-------------------------------main-------------------------------
if util.is_img(opt.media): if __name__ == '__main__':
print(transformer.convert(img,opt.gray)) if system_type == 'Windows':
elif util.is_video(opt.media): multiprocessing.freeze_support()
imgQueue = Queue(1) if util.is_img(opt.media):
timerQueue = Queue() 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 = Process(target=readvideo,args=(opt,imgQueue))
imgload_p.daemon = True imgload_p.daemon = True
imgload_p.start() imgload_p.start()
timer_p = Process(target=timer,args=(opt,timerQueue)) timer_p = Process(target=timer,args=(opt,timerQueue))
timer_p.daemon = True timer_p.daemon = True
timer_p.start() timer_p.start()
time.sleep(0.5) time.sleep(0.5)
subprocess.Popen('paplay ./tmp/tmp.wav', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 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): for i in range(int(opt.frame_num*opt.fps/opt.ori_fps)-1):
timerQueue.get() timerQueue.get()
img = imgQueue.get() img = imgQueue.get()
string = transformer.convert(img,opt.gray) string = transformer.convert(img,opt.gray)
t=threading.Thread(target=print,args=(string,)) t=threading.Thread(target=print,args=(string,))
t.start() t.start()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册