i am creating an app that converts long form video into short form video for tiktok or youtube shorts. but there is a problem. i dont know a lot about python. if u are willing to help me it would be so sweet. I am currently encountering multiple problems. here is the code:
import ffmpeg
from pytube import YouTube
from transformers import pipeline
import os
def download_video(video_url, save_path="C:\\Users\\Alexander\\Downloads\\maxflipking.mp4"):
try:
yt = YouTube(video_url)
yt_stream = yt.streams.get_highest_resolution()
download_path = yt_stream.download(filename=save_path)
print(f"Video downloaded at: {download_path}")
return download_path
except Exception as e:
print(f"Error: {e}")
return None
def extract_audio_from_video(video_path, output_path="extracted_audio.wav"):
try:
# Use ffmpeg-python with explicit path to ffmpeg
ffmpeg.input(video_path).output(output_path, format='wav').run(overwrite_output=True, ffmpeg='C:\\ffmpeg\\bin\\ffmpeg.exe')
print(f"Audio extracted to: {output_path}")
return output_path
except Exception as e:
print(f"Error extracting audio: {e}")
return None
def transcribe_audio_huggingface(audio_path):
try:
asr = pipeline('automatic-speech-recognition', model='openai/whisper-large')
transcription = asr(audio_path)["text"]
print(f"Transcription: {transcription}")
return transcription
except Exception as e:
print(f"Error during transcription: {e}")
return None
def process_youtube_video(video_url):
video_path = download_video(video_url)
if video_path:
audio_path = extract_audio_from_video(video_path)
if audio_path:
transcription = transcribe_audio_huggingface(audio_path)
return transcription
return None