Commit a2e8181d authored by mac's avatar mac

c

parent ed511fe0
Pipeline #390 canceled with stages
...@@ -149,7 +149,7 @@ def video2comix(args): ...@@ -149,7 +149,7 @@ def video2comix(args):
inputmp4 = jj(args.input_dir, args.filename + '.mp4') inputmp4 = jj(args.input_dir, args.filename + '.mp4')
outputmp4 = jj(args.output_dir, args.filename + '.mp4') outputmp4 = jj(args.output_dir, args.filename + '.mp4')
outputh264 = jj(args.output_dir, args.filename + '_h264.mp4') outputh264 = jj(args.output_dir, args.filename + '_h264.mp4')
print('video input: ', inputmp4)
vc = cv2.VideoCapture(inputmp4) vc = cv2.VideoCapture(inputmp4)
print('video open status:', vc.isOpened()) print('video open status:', vc.isOpened())
...@@ -159,10 +159,6 @@ def video2comix(args): ...@@ -159,10 +159,6 @@ def video2comix(args):
frame_height = int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT)) frame_height = int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT))
print('video w,h:', str(frame_width), ',', str(frame_height)) print('video w,h:', str(frame_width), ',', str(frame_height))
#total frames num
numFrames = int(vc.get(cv2.CAP_PROP_FRAME_COUNT))
print('video total Frames num:', str(numFrames))
# fps # fps
fps = int(vc.get(cv2.CAP_PROP_FPS)) fps = int(vc.get(cv2.CAP_PROP_FPS))
print('video fps:', str(fps)) print('video fps:', str(fps))
...@@ -171,6 +167,15 @@ def video2comix(args): ...@@ -171,6 +167,15 @@ def video2comix(args):
fps_flow = int(args.fps) # fps / 2 fps_flow = int(args.fps) # fps / 2
print('video output fps:', str(fps_flow)) print('video output fps:', str(fps_flow))
# total frames num
numFrames = int(vc.get(cv2.CAP_PROP_FRAME_COUNT))
print('video total Frames num:', str(numFrames))
step = fps / fps_flow #根据fps算要跳几帧,比如:24fpx/5fpx=4,即每4帧读取下,1秒大概读取4~5帧
totalNumFrames = numFrames / step
print('video output total Frames num:', str(totalNumFrames))
# MPEG can not play in web # MPEG can not play in web
fourcc = cv2.VideoWriter_fourcc(*'MP4V') #H264 avc1 fourcc = cv2.VideoWriter_fourcc(*'MP4V') #H264 avc1
...@@ -181,8 +186,8 @@ def video2comix(args): ...@@ -181,8 +186,8 @@ def video2comix(args):
print('video output w,h:', str(wh)) print('video output w,h:', str(wh))
flow_video = cv2.VideoWriter(outputmp4, fourcc, fps_flow, wh) flow_video = cv2.VideoWriter(outputmp4, fourcc, fps_flow, wh)
i = 0 i = 0
step = fps / fps_flow #根据fps算要跳几帧,比如:24fpx/5fpx=4,即每4帧读取下,1秒大概读取4~5帧
n = 0 #帧数 n = 0 #帧数
totalTime = 0
imgname = uuid.uuid4().hex imgname = uuid.uuid4().hex
while vc.isOpened(): while vc.isOpened():
vc.set(cv2.CAP_PROP_POS_FRAMES, n) # 截取指定帧数 vc.set(cv2.CAP_PROP_POS_FRAMES, n) # 截取指定帧数
...@@ -212,6 +217,8 @@ def video2comix(args): ...@@ -212,6 +217,8 @@ def video2comix(args):
#print('---------style_frame type=' , type(style_frame)) #print('---------style_frame type=' , type(style_frame))
if i == 0: if i == 0:
print('----------one frame time:',stylization_time,', style_frame type:',type(style_frame),',size',style_frame.shape) print('----------one frame time:',stylization_time,', style_frame type:',type(style_frame),',size',style_frame.shape)
print('frames:', i, ' / ', totalNumFrames, 'time:', stylization_time)
totalTime = totalTime + stylization_time
#img = np.asarray(style_frame) #img = np.asarray(style_frame)
flow_video.write(style_frame.astype('uint8')) flow_video.write(style_frame.astype('uint8'))
#flow_video.write(cv2.cvtColor(img,cv2.COLOR_RGB2BGR).astype('uint8')) #COLOR_BGR2RGB #flow_video.write(cv2.cvtColor(img,cv2.COLOR_RGB2BGR).astype('uint8')) #COLOR_BGR2RGB
...@@ -223,7 +230,7 @@ def video2comix(args): ...@@ -223,7 +230,7 @@ def video2comix(args):
flow_video.release() flow_video.release()
vc.release() vc.release()
#call(["ffmpeg", "-i", outputmp4, "-vcodec", "libx264", "-f", "mp4", outputh264]) #call(["ffmpeg", "-i", outputmp4, "-vcodec", "libx264", "-f", "mp4", outputh264])
print('finish') print('finish, totalTime= ',totalTime)
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment