0
from pytube import YouTube
from moviepy.editor import *

with open('test.txt') as f:
    lines = f.readlines()

for x in lines:
    yt = YouTube(x)
    yt.streams.filter(file_extension='mp4').first().download()

    mp4_file = f"{yt.title}.mp4"
    mp3_file = f"{yt.title}.mp4"

    videoclip = VideoFileClip(mp4_file)
    audioclip = videoclip.audio
    audioclip.write_audiofile(mp3_file)

    audioclip.close()
    videoclip.close()
    
    title = f"{yt.author} {yt.title}"
    print(title)

Trying to convert downloaded mp4 from Youtube videos to mp3 using pytube and moviepy. Downloading the mp4's works fine however I run into this error when the conversion part happens: https://i.stack.imgur.com/loxHh.png

Tried updating ffmpeg, but it didn't help.

  • Where did you acquire FFmpeg binary from? The error indicates that your FFmpeg is missing libx264 encoder, which comes with the 2 windows prebuilts linked from ffmpeg.org. – kesh May 30 '22 at 19:55
  • `f"{yt.title}.mp4"` for both the input and output filenames, probably won't be helping – Rolf of Saxony May 31 '22 at 06:58
  • Have you tried using `mp3_file = f"{yt.title}.mp3"` instead? – Damoiskii Jun 03 '22 at 21:49

0 Answers0