Commit 90ae19a4 authored by De Silva K.C.C.C's avatar De Silva K.C.C.C

video to audio implementation

parent 8cfd2b2d
import moviepy.editor as mp
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip
import os
import text_gen
def convert_video_to_audio(filename):
clip = mp.VideoFileClip(r"" + filename)
audio_file_name = str(filename).split('/')[-1].replace('.mp4', '.wav')
clip.audio.write_audiofile(r"audio_input/" + audio_file_name)
return text_gen.convert_audio_to_text("audio_input/" + audio_file_name)
def split_video_file(filename):
return_list = []
all_text = ''
required_video_file = filename
files = os.listdir('video_input')
for filename in files:
os.remove('video_input/' + filename)
total_length = VideoFileClip(required_video_file).duration
# print(total_length)
no_of_slices = int(total_length / 240) + 1
time_grid = []
for i in range(0, no_of_slices):
time_grid.append(i * 240)
for i in range(no_of_slices):
if i == len(time_grid) - 1:
# ffmpeg_extract_subclip(required_video_file, time_grid[i], total_length - time_grid[i],
# targetname='videos/' + str(i) + ".mp4")
pass
else:
ffmpeg_extract_subclip(required_video_file, time_grid[i], time_grid[i + 1],
targetname='video_input/' + str(i) + ".mp4")
text = convert_video_to_audio('video_input/' + str(i) + ".mp4")
all_text += text + ' '
return_list.append([i, text])
return return_list, all_text
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