Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"KeyError: 'video_fps'" when trying to convert youtube webm to mp3 #899

Closed
adhoc92 opened this issue Jan 11, 2019 · 13 comments
Closed

"KeyError: 'video_fps'" when trying to convert youtube webm to mp3 #899

adhoc92 opened this issue Jan 11, 2019 · 13 comments
Labels
audio Related to AudioClip, or handling of audio in general.

Comments

@adhoc92
Copy link

adhoc92 commented Jan 11, 2019

I'm downloading audio in mp4/web containers using Pytube, but I'm getting "KeyError: 'video_fps'" when trying to convert them to mp3 with moviepy.

Code:
import moviepy.editor as mp
from pytube import YouTube

#download video
youtubeurl = "https://www.youtube.com/watch?v=jYypQueS3ew&index=3&list=PL1nNuwHORUCPajRTocTSCJheaMzbWRu23&t=0s"
yt = YouTube(youtubeurl)
stream = yt.streams.filter(subtype='webm',only_audio=True).last().download("/home/jaws/Desktop/Stuff/Moosepy/temp/", filename="temp_audio")
print stream
print "Done!"

#convert to mp3
clip = mp.VideoFileClip("/home/jaws/Desktop/Stuff/Moosepy/temp/temp_audio.webm").subclip()
clip.audio.write_audiofile("audio.mp3")
print "Done!"

Output:

Traceback (most recent call last):
File "/home/jaws/Desktop/Stuff/Moosepy/test.py", line 13, in
clip = mp.VideoFileClip("/home/jaws/Desktop/Stuff/Moosepy/temp/temp_audio.webm").subclip()
File "/home/jaws/.local/lib/python2.7/site-packages/moviepy/video/io/VideoFileClip.py", line 91, in init
fps_source=fps_source)
File "/home/jaws/.local/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 34, in init
self.fps = infos['video_fps']
KeyError: 'video_fps'

Am I missing the codec? It converts mp4 and Webm video files to mp3 fine. It's just these weird audio files in webm/mp4 containers that won't convert. I guess since the FPS is 0, that's throwing up the error? How can I get around this?
`
Moviepy 0.2.3.5
Python 2.7.12

@keikoro keikoro added the audio Related to AudioClip, or handling of audio in general. label Jan 13, 2019
@adalbertopc
Copy link

I have the same issue. But im trying to convert mp4(only audio) to mp3

@lyraxvincent
Copy link

@adhoc92 provide the full path --> clip.audio.write_audiofile("/home/jaws/Desktop/Stuff/Moosepy/temp/audio.mp3")

@utkarshmttl
Copy link

@adalbertopc I have the same issue, I am trying to convert an audio-only mp4 to mp3. Were you ever able to solve your problem?

@tburrows13
Copy link
Collaborator

Linking #869

@tburrows13 tburrows13 added this to the Release v2.0.0 milestone Apr 27, 2020
@tburrows13
Copy link
Collaborator

@utkarshmttl it's a bit of a hack, but you could go to moviepy/video/io/ffmpeg_reader.py", line 34 and remove the line, or put a bit of logic around it to ignore it if "video_fps" is not a key in infos. I'll try and get it properly fixed for v2.0.

@lyraxvincent
Copy link

@adhoc92 provide the full path --> clip.audio.write_audiofile("/home/jaws/Desktop/Stuff/Moosepy/temp/audio.mp3")

have you tried this @utkarshmttl

@jangrd
Copy link

jangrd commented Aug 1, 2020

I got this problem when trying to do this for my personal mp3 yt downloader. I got the solution.
Instead of using VideoFileClip and its VideoFileClip.audio, just use AudioFileClip.
This worked for me. If you have trouble with this, use the full path instead of the relative path shown here.

# mp4 to mp3
clip = AudioFileClip('testfile.mp4')
clip.write_audiofile('testfile.mp3')
clip.close()

@tburrows13
Copy link
Collaborator

Thanks for the help, @sh0tzz. Presumably that’s because the video didn’t actually have any video, even though it was a mp4. It’s definitely something that could be fixed in MoviePy (or at least it could raise a better error), but that’s a good workaround for now.

Would you be able to share a file (or instructions on how to create one) that demonstrates the error?

@rajusurya39
Copy link

The error occurs when the video doesn't contain any visual content, ensure you are uploading a video which is not blank.

@2879786424
Copy link

2879786424 commented Sep 1, 2020

The error occurs when the video doesn't contain any visual content, ensure you are uploading a video which is not blank.

some videos doesn`t have visual content but have audio,how can I get the audio with mp3

@tburrows13
Copy link
Collaborator

Just import it as an AudioFileClip and it should work fine.

@2879786424
Copy link

it`s worked, thank you very much.

bzczb added a commit to bzczb/moviepy that referenced this issue Jan 27, 2023
@OsaAjani
Copy link
Collaborator

Thank you for your contributions and for reporting issues in this repository. With the release of v2, which introduces significant changes to the codebase and API, we’ve reviewed the backlog of open PRs and issues. Due to the length of the backlog and the likelihood that many of these are either fixed or no longer applicable, we’ve made the decision to close all previous PRs and issues.

If you believe that any of these are still relevant to the current version or if you'd like to reopen a related discussion, please feel free to create a new issue or pull request, referencing the old one.

Thank you for your understanding and continued support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Related to AudioClip, or handling of audio in general.
Projects
None yet
Development

No branches or pull requests

10 participants