首页 > 编程语言 >python把mp4转mp3

python把mp4转mp3

时间:2023-04-04 10:46:03浏览次数:34  
标签:listdir name python mp4 mp3 file path out

预先下载

Pip install moviepy

from moviepy.editor import *

def outputmp3(input_path, output_path):
    listdir = os.listdir(input_path)   # 获得路径所有文件名
    mp4namelist = [name for name in listdir if name.endswith('.mp4')]   # 筛选出所有MP4

    for file in mp4namelist:
        filepath = os.path.join(input_path, file)  # mp4文件路径
        video = VideoFileClip(filepath)

        # 构造mp3文件名
        file_list = list(file)
        file_list[-1] = '3'
        file_name_mp3 = ''.join(file_list)

        out_listdir = []
        out_filepath = ''
        if len(output_path) == 0:
            # 输出MP3文件到默认路径
            out_listdir = listdir
            out_filepath = os.path.join(input_path, file_name_mp3)
        else:
            # 输出MP3文件到指定路径
            out_listdir = os.listdir(output_path)
            out_filepath = os.path.join(output_path, file_name_mp3)

        # 检查文件是否已经存在
        if file_name_mp3 in out_listdir:
            continue
        audio = video.audio
        audio.write_audiofile(out_filepath)


if __name__ == '__main__':
    input_path = r'E:\texttt\aaa'  # 绝对地址
    output_path = r'E:\texttt\bbb'  # 不传输出路径则默认生成在input_path下
    outputmp3(input_path, output_path)

标签:listdir,name,python,mp4,mp3,file,path,out
From: https://www.cnblogs.com/duoba/p/17285613.html

相关文章

  • Python __ Pandas
    简介可以看做是Excel是基于Numpy的.优点:处理表格数据(混杂数据)需要引用:importpandasaspdSeries(无用)类似于Numpy的一维数组优点:相较于Nump索引功能强大输出默认带索引:(当为字典是,,默认键是索引)s4=pd.Series([9.53,9.62,9.72])创建时可以指定索引:s5=pd.Series([1,np......
  • Python3内置函数之H系列
    1、hasattr()hasattr()是Python内置函数之一,用于检查一个对象是否具有指定的属性或方法。 2、hash()在Python中,hash()函数用于获取给定对象的哈希值(散列值),即对象的唯一标识符。哈希值是一个整数,具有以下特点:对于同一个对象,在程序的不同执行期间,哈希值保持不变。对于......
  • 全网最详细中英文ChatGPT-GPT-4示例文档-智能AI辅助写作从0到1快速入门——官网推荐的
    目录Introduce简介setting设置Prompt提示Sampleresponse回复样本APIrequest接口请求python接口请求示例node.js接口请求示例curl命令示例json格式示例其它资料下载ChatGPT是目前最先进的AI聊天机器人,它能够理解图片和文字,生成流畅和有趣的回答。如果你想跟上AI时代的潮流......
  • Python字符串模糊匹配
    四种模糊匹配方法1、ratio()——使用纯LevenshteinDistance进行匹配。2、partial_ratio()——基于最佳的子串(substrings)进行匹配3、token_set_ratio——对字符串进行标记(tokenizes)并在匹配之前按字母顺序对它们进行排序 4、token_set_ratio——对字符串进行标记(tokenizes)并......
  • 全网最详细中英文ChatGPT-GPT-4示例文档-智能AI写作从0到1快速入门——官网推荐的48种
    目录Introduce简介setting设置Prompt提示Sampleresponse回复样本APIrequest接口请求python接口请求示例node.js接口请求示例curl命令示例json格式示例其它资料下载ChatGPT是目前最先进的AI聊天机器人,它能够理解图片和文字,生成流畅和有趣的回答。如果你想跟上AI时代的潮流......
  • Python GUI 库介绍-PySimpleGUI
    1.pipinstallPySimpleGUI2.codingimportPySimpleGUIassglayout=[[sg.Text("HELLOPySimpleGUI")],[sg.Text("姓名"),sg.InputText("张喆坤")],[sg.Text("性别"),sg.InputText("N\A")],[sg.Text(&......
  • 听说Python有鸡肋?一起聊聊...
    听说是鸡肋❝一直以来,关于Python的多线程和多进程是否是鸡肋的争议一直存在,今晚抽空谈谈我的看法,以下是我的观点:❞对于多线程:Python的多线程库threading在某些情况下确实是鸡肋的,这是因为Python的全局解释器锁(GlobalInterpreterLock,GIL)导致了多线程的并发性能不能......
  • Multimedia (MP3, MPEG-4, AVI, DiVX, etc.) support in Ubuntu 12.04 (Precise)
    Whydoesn’tUbuntusupportMP3‘outofthebox’?UbuntucannotincludesupportforMP3orDVDvideoplaybackorrecording.MP3formatsarepatented,andthepatentholdershavenotprovidedthenecessarylicenses.Ubuntualsoexcludesothermultimediasof......
  • 利用Python写入CSV文件的方法
    利用Python写入CSV文件的方法  #!/usr/bin/envpython#_*_coding:utf-8_*_importcsvcsvfile=file('test.csv','wb')csvfile.write(u'\ufeff'.encode('utf8'))writer=csv.writer(csvfile)writer.writerow(['id&......
  • Window下,利用Anaconda2创建jupyter-notebook的python3环境方法
    转载自:https://www.cnblogs.com/ljy2013/p/8351067.html随着深度学习的火热,越来越多的人去学习和了解这门技术。而做算法的同学为了能够更快,更高效的写出相关的深度学习算法出来,需要比较方便的开发环境。今天主要介绍一下在jupyternotebook中,新增python3的环境,从而可以使用tenso......