手记

MP4 TO MP3

# coding=UTF-8
import os, sys
import subprocess
from scipy.io import wavfile

def ffmpeg_VideoToAudio(VideoPath, WavPath):
    # 提取视频路径下所有文件名
    videos = os.listdir(VideoPath)
    count = 0
    for video in videos:
        # 提取视频的全路径名(含路径+文件名)
        video_path = '"'+VideoPath + '\\' + video+'"'
        # 合成输出音频的全路径名(不含后缀)
        wav_path = '"'+WavPath + '\\' + os.path.splitext(video)[0]+'.mp3"'
        # 提取视频中的音频信息
        # strcmd = "ffmpeg -i " + video_path + " -f wav " + wav_path + ".wav"
        
        strcmd = "ffmpeg -i " + video_path + " -f mp3 " + wav_path
        
        print(strcmd)
        subprocess.call(strcmd, shell=True)

VideoPath = r'D:\py\videos'
WavPath = r'D:\py\audios'
ffmpeg_VideoToAudio(VideoPath,WavPath)
0人推荐
随时随地看视频
慕课网APP