亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我正在嘗試使用 MoviePy 模塊將視頻 mp4 文件轉換為音頻 mp3 格式

我正在嘗試使用 MoviePy 模塊將視頻 mp4 文件轉換為音頻 mp3 格式

炎炎設計 2023-02-12 18:59:50
def download_audio():#try:    b2.config(text="Please wait...")    b2.config(state=DISABLED)    stream = yt.streams.filter(res="480p")    path = filedialog.askdirectory()    if path == None:        return    stream[0].download(path)    for i in os.listdir(path):        os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))    title = yt.title.replace(' ','_')    print(title)    print(path)    video = VideoFileClip(os.path.join(path+"//"+title+".mp4"))    print(video)    video.audio.write_audiofile(os.path.join(path+"//"+title+".mp3"))這是錯誤消息 屬性錯誤:NoneType 對象沒有屬性 write_audiofile
查看完整描述

3 回答

?
SMILET

TA貢獻1796條經驗 獲得超4個贊

嘗試:


def download_audio():

#try:

    b2.config(text="Please wait...")

    b2.config(state=DISABLED)

    stream = yt.streams.filter(res="480p")

    path = filedialog.askdirectory()

    if path == None:

        return

    stream[0].download(path)

    for i in os.listdir(path):

        os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))

    title = yt.title.replace(' ','_')

    print(title)

    print(path)

    video = VideoFileClip(os.path.join(path,title+".mp4"))

    print(video)

    video.audio.write_audiofile(os.path.join(path,title+".mp3"))

路徑需要使用逗號而不是“//”在 os.path 中建立。


查看完整回答
反對 回復 2023-02-12
?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

弄清楚了。實際上 streams.filter("480p") 給了我一個沒有音頻的只有視頻的流,這就是為什么出現非類型錯誤,因為它沒有音頻對象。通過執行 streams.filter(progressive=True) 解決了它。


def download_audio():

#try:

b2.config(text="Please wait...")

b2.config(state=DISABLED)

stream = yt.streams.filter(progressive=True)

path = filedialog.askdirectory()

if path == None:

    return

stream[0].download(path)

for i in os.listdir(path):

    os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))

title = yt.title.replace(' ','_')

print(title)

print(path)

video = VideoFileClip(os.path.join(path+"//"+title+".mp4"))

print(video)

video.audio.write_audiofile(os.path.join(path+"//"+title+".mp3"))


查看完整回答
反對 回復 2023-02-12
?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

嘗試video.write_audiofile(os.path.join(path+"//"+title+".mp3"))

您最好使用 ffmpeg 轉換視頻或使用 opencv 進行所有視頻管理。


查看完整回答
反對 回復 2023-02-12
  • 3 回答
  • 0 關注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號