首页 > 解决方案 > 在python中将视频转换为音频

问题描述

我尝试制作一个转换器应用程序,它可以从 youtube 下载 .3gpp 格式的视频并将其转换为 mp3,但我有一些关于权限的问题,我现在真的不关心 windows 和 python 权限。

import pytube
import moviepy.editor as mp

while True:
    url = input("Video url: ")
    print("Downloading video....")
    youtube = pytube.YouTube(url)
    video = youtube.streams.first()
    video.download(r'C:\Users\Silver\Downloads\video.3gpp')
    print("Converting video....") 
    clip = mp.VideoFileClip(r"C:\Users\Silver\Downloads\video.3gpp")
    clip.audio.write_audiofile(r"C:\Users\Silver\Desktop\INFO\PythonFiles\Python\Youtube MP3 Converter\mp3 conv")

错误:

Traceback (most recent call last):
  File "C:\Users\Silver\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 285, in ffmpeg_parse_infos
    line = [l for l in lines if keyword in l][index]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Silver\Desktop\INFO\PythonFiles\Python\Youtube MP3 Converter\Mp3Conv.py", line 12, in <module>
    clip = mp.VideoFileClip(r"C:\Users\Silver\Downloads\video.3gpp")
  File "C:\Users\Silver\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 88, in __init__
    self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
  File "C:\Users\Silver\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 35, in __init__
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
  File "C:\Users\Silver\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 289, in ffmpeg_parse_infos
    raise IOError(("MoviePy error: failed to read the duration of file %s.\n"
OSError: MoviePy error: failed to read the duration of file C:\Users\Silver\Downloads\video.3gpp.
Here are the file infos returned by ffmpeg:

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt

  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100

C:\Users\Silver\Downloads\video.3gpp: Permission denied

标签: pythonwindows-10python-3.9moviepypytube

解决方案


推荐阅读