Python extract wav from video file

后端 未结 5 1426
执念已碎
执念已碎 2020-12-02 11:24

Related:

How to extract audio from a video file using python?

Extract audio from video as wav

How to rip the audio from a video?

My question

5条回答
  •  猫巷女王i
    2020-12-02 12:21

    or example extract mp3 from

    import os
    
    VIDEOS_PATH = '/Users/****/videos'
    VIDEOS_EXTENSION = '.webm'  # for example
    AUDIO_EXT = 'wav'
    
    EXTRACT_VIDEO_COMMAND = ('ffmpeg -i "{from_video_path}" '
                             '-f {audio_ext} -ab 192000 '
                             '-vn "{to_audio_path}"')
    
    os.chdir(VIDEOS_PATH)
    files = os.listdir(VIDEOS_PATH)
    for f in files:
        if not f.endswith(VIDEOS_EXTENSION):
            continue
    
        audio_file_name = '{}.{}'.format(f, AUDIO_EXT)
        command = EXTRACT_VIDEO_COMMAND.format(
            from_video_path=f, audio_ext=AUDIO_EXT, to_audio_path=audio_file_name,
        )
        os.system(command)
    

提交回复
热议问题