def extract_highlights(file_paths): """ :param file_paths: 동영상 경로 리스트 :return: 추출한 하이라이트 동영상 경로 리스트 """ max_highlights = [] min_highlights = [] for file_path in file_paths: video_clip = VideoFileClip(file_path) audio_clip = video_clip.audio src_audio_file_name = get_random_name('wav') audio_clip.write_audiofile(src_audio_file_name) source_wave = wave.read(src_audio_file_name) stereo_channel_wave = source_wave[1].T[1] normalize_wave = [(ele / 2 ** 8.) * 2 - 1 for ele in stereo_channel_wave] # this is 8-bit track, now normalized on [-1,1) fourier_transform_wave = fft(normalize_wave) # calculate fourier transform (complex numbers list) normalize_time = len(fourier_transform_wave) / video_clip.duration argmax_frequency = np.argmax(fourier_transform_wave) / normalize_time + 0.5 argmin_frequency = np.argmin(abs(fourier_transform_wave)) / normalize_time + 0.5 max_highlight_path = max_highlights.append(get_random_name('mp4')) min_highlight_path = min_highlights.append(get_random_name('mp4')) video_clip.subclip(argmax_frequency - (HIGHLIGHT_LENGTH/2), argmax_frequency + (HIGHLIGHT_LENGTH/2)).write_videofile(max_highlight_path, codec='libx264', audio_codec='aac') video_clip.subclip(argmin_frequency - (HIGHLIGHT_LENGTH/2), argmin_frequency + (HIGHLIGHT_LENGTH/2)).write_videofile(min_highlight_path, codec='libx264', audio_codec='aac') video_clip.close() return max_highlights, min_highlights
def edit_sounds(path, pitch, length): sr = 44100 output_path = get_random_name('wav') speed = HIGHLIGHT_LENGTH / length y, sr = librosa.load(path, sr=sr) write_wav(output_path, time_stretch(pitch_shift(y, sr, pitch), speed), sr) return output_path
def overwrite_audio(video_path, audio_path, silence): """ :param video_path: 영상에 쓰일 하이라이트 영상 경로 :param audio_path: 음계가 조정된 오디오 파일 경로 :param silence: 오디오 파일 제거 :return: 조정된 하이라이트 영상 경로 """ # Access video file and audio file video_clip = VideoFileClip(video_path) audio_clip = AudioFileClip(audio_path) # Create random file name video_path = get_random_name('mp4') # Adjust video speed to sync with audio file adjusted_video = video_clip.fx(vfx.speedx, final_duration=audio_clip.duration) # Overwrite video audio if silence: adjusted_video.audio = None adjusted_video.write_videofile(video_path, codec='libx264', audio_codec='aac') else: adjusted_video.audio = audio_clip adjusted_video.write_videofile(video_path, codec='libx264', audio_codec='aac') return video_path
def merge_videos(file_paths): clip_list = [VideoFileClip(file_path) for file_path in file_paths] final_clip = concatenate_videoclips(clip_list) file_path = get_random_name('mp4') # Insert background audio final_clip.audio = add_background_audio(final_clip.audio) final_clip.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path
def extract_audio(video_path): """ :param video_path: 영상에 쓰일 하이라이트 영상 경로 :return: 영상에서 추출된 오디오 파일 경로 """ # Create random file name audio_path = get_random_name('wav') # Access video file video_clip = VideoFileClip(video_path) # Extract audio file audio_clip = video_clip.audio audio_clip.write_audiofile(audio_path) return audio_path
def downloader(file_urls): file_paths = [] for url in file_urls: file_name = get_random_name('mp4') file_paths.append(file_name) request = requests.get(url, stream=True) if request.status_code == 200: with open(file_name, 'wb') as f: for chunk in request.iter_content(1024): f.write(chunk) """ :param file_urls: 사용자가 업로드한 동영상 파일 url 리스트 :return: 다운받은 절대 경로 리스트 """ return file_paths
def _invert_colors(video): out = video.fx(vfx.invert_colors) file_path = get_random_name('mp4') out.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path
def _stay(video): file_path = get_random_name('mp4') video.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path
def _rotate_270(video): out = video.fx(vfx.rotate, angle=270) file_path = get_random_name('mp4') out.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path
def _mask_color(video): out = video.fx(vfx.mask_color, color=[255, 0, 0], thr=100, s=5) # out = video.on_color(color=(255, 255, 0)) file_path = get_random_name('mp4') out.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path
def _colorx(video): out = video.fx(vfx.colorx, factor=2) file_path = get_random_name('mp4') out.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path
def _black_white(video): out = video.fx(vfx.blackwhite) file_path = get_random_name('mp4') out.write_videofile(file_path) return file_path
def _flip_y(video): out = video.fx(vfx.mirror_y) file_path = get_random_name('mp4') out.write_videofile(file_path, codec='libx264', audio_codec='aac') return file_path