Windows下python+ffmpeg實(shí)現(xiàn)批量提取、切割視頻中的音頻

廢話不說(shuō),直接上代碼

#遍歷所有mp4文件名->文件名改為字母形式->fffmpeg批量提取音頻、切割音頻->改回中文名

import os

import subprocess

current = os.getcwd()

dirs = os.listdir(current)

for i in dirs:

? ? if os.path.splitext(i)[1] == ".mp4":

? ? ? ? #bname = str(os.path.splitext(i)[0].encode('utf-8')).replace('\\','%').replace(' ','_')

? ? ? ? os.rename(i,'temp.mp4')

? ? ? ? getmp3 = 'ffmpeg -i temp.mp4 -f mp3 -vn temp.mp3'

? ? ? ? cutmp3 = 'ffmpeg -i temp.mp3 -ss 00:00:15 -acodec copy tempcut.mp3'

? ? ? ? returnget = subprocess.call(getmp3,shell = True)

? ? ? ? returncut = subprocess.call(cutmp3,shell = True)

? ? ? ? os.remove('temp.mp3')

? ? ? ? os.rename('tempcut.mp3',os.path.splitext(i)[0] + '.mp3')

? ? ? ? os.rename('temp.mp4',i)

? ? ? ? print(returnget,returncut)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容