def video_2_png(seg_length, seg_id, video): # Check path and files existed or not filemanager.make_sure_path_exists(tmp_path) filemanager.make_sure_path_exists(output_path) filemanager.make_sure_path_exists(frame_path) # download the videos from encoding server #req_ts = time.time() #start_recv_ts = download_video_from_server(seg_length, seg_id, video) #end_recv_ts = time.time() # clip video into frames path = tmp_path + str(video) + "_equir_" + str(seg_id) + ".mp4" subprocess.call('mv %s %s' % (output_path + "output_" + str(seg_id) + ".mp4", path), shell=True) vidcap = cv2.VideoCapture(path) success, frame = vidcap.read() count = 1 while success: # save frame as PNG format cv2.imwrite(frame_path + "frame%d.png" % count, frame, [cv2.IMWRITE_PNG_COMPRESSION, 0]) success, frame = vidcap.read() print >> sys.stderr, "Clip a new frame:", count count += 1
def video_2_image(path): # Check path and files existed or not filemanager.make_sure_path_exists(tmp_path) filemanager.make_sure_path_exists(output_path) filemanager.make_sure_path_exists(frame_path) vidcap = cv2.VideoCapture(path) success, frame = vidcap.read() count = 1 success = True while success: # save frame as PNG format cv2.imwrite(frame_path + "frame%d.png" % count, frame) success, frame = vidcap.read() print "Clip a new frame:", count count += 1
def video_2_image(seg_length, user_id, seg_id, video, bitrate): global tmp_path tmp_path = "./tmp_" + video + '_user' + user_id + '_' + str( seg_id) + '_' + bitrate + '_VPR/' global output_path output_path = "./output_" + video + '_user' + user_id + '_' + str( seg_id) + '_' + bitrate + '_VPR/' global frame frame_path = "./frame_" + video + '_user' + user_id + '_' + str( seg_id) + '_' + bitrate + '_VPR/' # Check path and files existed or not filemanager.make_sure_path_exists(tmp_path) filemanager.make_sure_path_exists(output_path) filemanager.make_sure_path_exists(frame_path) # clip video into frames mp4_path = tmp_path + str(video) + "_equir_" + str(seg_id) + ".mp4" yuv_path = tmp_path + str(video) + "_equir_" + str(seg_id) + ".yuv" the_file = "output_" + video + '_user' + user_id + '_' + str( seg_id) + '_' + bitrate + "_VPR.mp4" subprocess.call('mv %s %s' % (output_path + the_file, mp4_path), shell=True) conv2yuv = "ffmpeg -y -i " + mp4_path + " -c:v rawvideo -pix_fmt yuv420p " + yuv_path subprocess.call(conv2yuv, shell=True) vidcap = cv2.VideoCapture(mp4_path) if vidcap.isOpened(): width = int(vidcap.get(cv2.CAP_PROP_FRAME_WIDTH)) # get width height = int(vidcap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # get height fps = int(vidcap.get(cv2.CAP_PROP_FPS)) # get fps length = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT)) # get length depth = 3 ratio = 2 # YUV420: (4Y+1Cb+1Cr) = 12 bits per pixel frame_size = int(width * height * depth / ratio) # bytes per frame # clip each frame form yuv video with open(yuv_path, 'rb') as vid_in: for i in range(1, int(length) + 1): # read data from yuv file frame_data = vid_in.read(frame_size) # output it as 1-frame long yuv file filename = frame_path + "frame" + str(i) + ".yuv" output_frame = open(filename, "w") output_frame.write(frame_data) print >> sys.stderr, "Clip a new frame:", filename
def mixed_tiles_quality(no_of_tiles, seg_length, seg_id, VIDEO, low=[], medium=[], high=[]): # Check path and files existed or not filemanager.make_sure_path_exists(tmp_path) filemanager.make_sure_path_exists(output_path) filemanager.clean_exsited_files(tmp_path, output_path, seg_id) # Create a list to store all the videos video_list = [] video_list.append("dash_set1_init.mp4") print >> sys.stderr, 'dash_set1_init.mp4' # Sort the tracks into tiled videos list for i in range(1, no_of_tiles + 2, 1): if i == 1: # track1 is needed debug_msg = "video_tiled_" + "low_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "low_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") elif i in low: debug_msg = "video_tiled_" + "low_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "low_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") elif i in medium: debug_msg = "video_tiled_" + "medium_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "medium_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") elif i in high: debug_msg = "video_tiled_" + "high_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "high_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") else: debug_msg = "video_tiled_" + "low_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "low_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") # download the videos from encoding server req_ts = time.time() start_recv_ts = download_tiled_video_from_server(VIDEO, no_of_tiles, seg_length, video_list) end_recv_ts = time.time() # Concatenate init track and each tiled tracks for i in range(0, len(video_list), 1): subprocess.call('cat %s >> temp_%s.mp4' % ((tmp_path + video_list[i]), seg_id), shell=True) # Extract the raw hevc bitstream subprocess.call('MP4Box -raw 1 temp_%s.mp4' % seg_id, shell=True) # Repackage and generate new ERP video subprocess.call( 'MP4Box -add temp_%s_track1.hvc:fps=%s -inter 0 -new output_%s.mp4' % (seg_id, FPS, seg_id), shell=True) # Move all the files into folders subprocess.call('mv temp_%s.mp4 %s' % (seg_id, tmp_path), shell=True) subprocess.call('mv temp_%s_track1.hvc %s' % (seg_id, tmp_path), shell=True) subprocess.call('mv output_%s.mp4 %s' % (seg_id, output_path), shell=True) return (req_ts, start_recv_ts, end_recv_ts)
def only_fov_tiles(no_of_tiles, seg_length, seg_id, VIDEO, low=[], medium=[], high=[]): # Check path and files existed or not filemanager.make_sure_path_exists(tmp_path) filemanager.make_sure_path_exists(output_path) filemanager.clean_exsited_files(tmp_path, output_path, seg_id) video_list = [] video_list.append("dash_set1_init.mp4") print >> sys.stderr, 'dash_set1_init.mp4' # Sort the tracks into tiled videos list for i in range(1, no_of_tiles + 2, 1): if i == 1: # track1 is needed debug_msg = "video_tiled_" + "low_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "low_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") elif i in low: debug_msg = "video_tiled_" + "low_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "low_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") elif i in medium: debug_msg = "video_tiled_" + "medium_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "medium_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") elif i in high: debug_msg = "video_tiled_" + "high_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "high_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") else: debug_msg = "video_tiled_" + "low_" + "dash_" + "track" + str( i) + "_" + str(seg_id) + ".m4s" #print >> sys.stderr, debug_msg video_list.append("video_tiled_" + "low_" + "dash_" + "track" + str(i) + "_" + str(seg_id) + ".m4s") # download the videos from encoding server req_ts = time.time() start_recv_ts = download_tiled_video_from_server(VIDEO, no_of_tiles, seg_length, video_list) end_recv_ts = time.time() # Concatenate init track and each tiled tracks for i in range(0, len(video_list), 1): subprocess.call('cat %s >> temp_%s.mp4' % ((tmp_path + video_list[i]), seg_id), shell=True) # Parse the viewed tile list to create remove list remove_track = [] if low: for i in range(3, no_of_tiles + 2, 1): if i not in low: remove_track.append("-rem %s" % i) elif medium: for i in range(3, no_of_tiles + 2, 1): if i not in medium: remove_track.append("-rem %s" % i) elif high: for i in range(3, no_of_tiles + 2, 1): if i not in high: remove_track.append("-rem %s" % i) else: print >> sys.stderr, "It should not be here." # convert reomve list to string cmd = "" for i in range(0, len(remove_track), 1): cmd = cmd + str(remove_track[i]) + " " # Remove unwatched tiles subprocess.call('MP4Box %s temp_%s.mp4 -out lost_temp_%s.mp4' % (cmd, seg_id, seg_id), shell=True) # Extract the raw hevc bitstream subprocess.call('MP4Box -raw 1 lost_temp_%s.mp4' % seg_id, shell=True) # Repackage and generate new ERP video subprocess.call( 'MP4Box -add lost_temp_%s_track1.hvc:fps=%s -inter 0 -new output_%s.mp4' % (seg_id, FPS, seg_id), shell=True) # Move all the files into folders subprocess.call('mv temp_%s.mp4 %s' % (seg_id, tmp_path), shell=True) subprocess.call('mv lost_temp_%s.mp4 %s' % (seg_id, tmp_path), shell=True) subprocess.call('mv lost_temp_%s_track1.hvc %s' % (seg_id, tmp_path), shell=True) subprocess.call('mv output_%s.mp4 %s' % (seg_id, output_path), shell=True) return (req_ts, start_recv_ts, end_recv_ts)