def video_shot(args): start_time = time.time() captures = {} cut_list = [] cut_video = CutVideo() init_extract = InitExtract() ncpus = cpu_count() queue_list = [] sensitivity = 0.35 temporary = Temporary() video_process = VideoProcess() try: file_input_name = args[args.index("-i") + 1] output_directory = args[args.index("-o") + 1] except ValueError: sys.exit("Usage: videoShot -i <inputFile> -o <outputDirectory>") temporary_directory = temporary.createDirectory() print "Converting video to ogg..." start_time2 = time.time() convert_video_to_ogg(file_input_name, temporary_directory) start_time3 = time.time() ogg_video_path = os.path.join(temporary_directory, "video_converted.ogg") output_segmentation_directory = output_directory + "/segmentation_video/" file_name_save = output_segmentation_directory + "/transitions_video/" file_video_save = output_segmentation_directory + "/parts_videos/" file_audio_save = output_segmentation_directory + "/video_audio/" thumbnails_save_path = output_segmentation_directory + "/thumbnails/" create_directory( [output_segmentation_directory, file_name_save, file_video_save, file_audio_save, thumbnails_save_path] ) file_input_name = ogg_video_path capture = init_extract.createCapture(file_input_name) video_duration = get_video_duration(ogg_video_path) fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS) total_frames = round(video_duration * fps, 0) frames_bloc = int(total_frames / ncpus) split_video(temporary_directory, ncpus, video_duration, ogg_video_path) list_videos_path = get_videos_path(temporary_directory) captures[1] = init_extract.createCapture(list_videos_path[0]) cvSaveImage(file_name_save + "trans_time_1.jpg", init_extract.initFrameCapture(captures[1])) for i in range(2, ncpus + 1): captures[i] = init_extract.createCapture(list_videos_path[i - 1]) print "Finding transitions..." video_process.create_video_process( captures, sensitivity, frames_bloc, file_input_name, file_name_save, file_video_save, ncpus, queue_list ) for i in range(ncpus): cut_list.extend(queue_list[i].get()) cut_list = [round(x, 6) for x in cut_list] time_cut_list = cut_video.position_cut_list(cut_list, ncpus) print "Generating Segments..." video_process.create_cut_process(file_input_name, file_video_save, time_cut_list, ncpus) get_output_audio(file_audio_save, ogg_video_path) get_video_thumbnails(file_video_save, thumbnails_save_path) temporary.removeDirectory(temporary_directory) print print "Conversion Time: %.2f s" % (start_time3 - start_time2) print "Segmentation Time: %.2f s" % ((time.time() - start_time) - (start_time3 - start_time2)) print "Segmentation completed in : %.2f s" % (time.time() - start_time)
def videoShot(args): w = time.time() file_atual = os.getcwd() initExtract = InitExtract() videoprocess = VideoProcess() shotvideo = ShotVideo() cutvideo = CutVideo() captures = {} cut_list=[] sensitivity = 0.35 ncpus = cpu_count() queue_list=[] FileName = args[args.index('-i') + 1] output = args[args.index('-o') + 1] fileNameSave = (output + '/transitions_' + 'video' + '/') fileVideoSave = (output + '/parts_' + 'video'+'/') for files in (fileNameSave, fileVideoSave): try: shutil.rmtree(files) except: pass os.mkdir(files) capture = initExtract.createCapture(FileName) total_frames = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT) # if utilizado para quando o video nao possui o metadado de total frame if total_frames == 0: total_frames = shotvideo.contFrames(capture) frames_bloc = int(total_frames / ncpus) captures[1] = initExtract.createCapture(FileName) cvSaveImage(fileNameSave + 'transition25.jpg', initExtract.initFrameCapture(captures[1])) for i in range(2, ncpus + 1): captures[i] = initExtract.createCapture(FileName) captures[i] = initExtract.pass_frames(captures[i], frames_bloc, i - 1) j = time.time() videoprocess.create_video_process(captures,sensitivity,frames_bloc,FileName,fileNameSave,fileVideoSave,file_atual,ncpus,queue_list) for i in range(ncpus): cut_list.extend(queue_list[i].get()) cut_list = [round(x,6) for x in cut_list] corte = cutvideo.position_cut_list(cut_list,ncpus) videoprocess.create_cut_process(FileName,fileVideoSave,file_atual,corte,ncpus) print "A segmentacao foi concluida em : %.2f segundos " % (time.time() - w)
def video_shot(args): start_time = time.time() captures = {} cut_list = [] cut_video = CutVideo() init_extract = InitExtract() ncpus = cpu_count() queue_list = [] sensitivity = 0.35 temporary = Temporary() video_process = VideoProcess() try: file_input_name = args[args.index('-i') + 1] output_directory = args[args.index('-o') + 1] except ValueError: sys.exit('Usage: videoShot -i <inputFile> -o <outputDirectory>') temporary_directory = temporary.createDirectory() print "Converting video to ogg..." start_time2 = time.time() convert_video_to_ogg(file_input_name, temporary_directory) start_time3 = time.time() ogg_video_path = os.path.join(temporary_directory, "video_converted.ogg") output_segmentation_directory = output_directory + '/segmentation_video/' file_name_save = (output_segmentation_directory + '/transitions_video/') file_video_save = (output_segmentation_directory + '/parts_videos/') file_audio_save = (output_segmentation_directory + '/video_audio/') thumbnails_save_path = (output_segmentation_directory + '/thumbnails/') create_directory([output_segmentation_directory, file_name_save, file_video_save, file_audio_save, thumbnails_save_path]) file_input_name = ogg_video_path capture = init_extract.createCapture(file_input_name) video_duration = get_video_duration(ogg_video_path) fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS) total_frames = round(video_duration * fps, 0) frames_bloc = int(total_frames / ncpus) split_video(temporary_directory, ncpus, video_duration, ogg_video_path) list_videos_path = get_videos_path(temporary_directory) captures[1] = init_extract.createCapture(list_videos_path[0]) cvSaveImage(file_name_save + 'trans_time_1.jpg', init_extract.initFrameCapture(captures[1])) for i in range(2, ncpus + 1): captures[i] = init_extract.createCapture(list_videos_path[i-1]) print "Finding transitions..." video_process.create_video_process(captures, sensitivity, frames_bloc, file_input_name, file_name_save, file_video_save, ncpus, queue_list) for i in range(ncpus): cut_list.extend(queue_list[i].get()) cut_list = [round(x,6) for x in cut_list] time_cut_list = cut_video.position_cut_list(cut_list, ncpus) print "Generating Segments..." video_process.create_cut_process(file_input_name, file_video_save, time_cut_list, ncpus) get_output_audio(file_audio_save, ogg_video_path) get_video_thumbnails(file_video_save, thumbnails_save_path) temporary.removeDirectory(temporary_directory) print print "Conversion Time: %.2f s" % (start_time3 - start_time2) print "Segmentation Time: %.2f s" % ((time.time() - start_time) - (start_time3 - start_time2)) print "Segmentation completed in : %.2f s" % (time.time() - start_time)