DDR爱好者之家 Design By 杰米

一段把mp4中的音频提取为mp3并保存在原目录的python脚本

需要提前安装好ffmpeg 转换为单线程,耗时较长

github: https://github.com/cuifeiran/extract-mp3-from-mp4

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time   : 2020/2/26 17:36
# @Author  : CuiFeiran
# @FileName : tool.py
# @Software : PyCharm
# @email  :cui2025@126.com
# @Blog   : https://blog.csdn.net/qq_33273956
# @bilibili : https://space.bilibili.com/368768799
import os
import glob
from pydub import AudioSegment
wenjianjia = []
path = input('请输入要转码的父文件夹路径:')
for root, dirs, files in os.walk(path):
  wenjianjia.append(root)
wjj = wenjianjia
for dir in wjj:
  video_dir = dir
  extension_list = ('*.mp4', '*.flv')
  i = 1
  os.chdir(video_dir)
  for extension in extension_list:
    for video in glob.glob(extension):
      mp3_filename = os.path.splitext(os.path.basename(video))[0] + '.mp3'
      AudioSegment.from_file(video).export(mp3_filename, format='mp3')
      print('已转码', str(i), '个视频!')
      i += 1
  #
  # for infile in glob.glob(os.path.join(video_dir, '*.mp4')):
  #   os.remove(infile)

总结

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米