代码之家  ›  专栏  ›  技术社区  ›  RobyJ

命令的python-ffmpeg配置

  •  -1
  • RobyJ  · 技术社区  · 1 年前

    我想将mp3文件转换为mp3,但要使用我的设置。有人能帮我创建python代码或命令cmd用ffmpeg执行这样的操作吗?我有数百个mp3文件,所以我需要自动化它。设置在下图中。

    Audacity Configuration

    我试着配置它,但在ffmpeg文档中查找有关的信息时遇到了问题 bit rate mode quality 设置。

    1 回复  |  直到 1 年前
        1
  •  1
  •   Dexter Mandark    1 年前
    import subprocess
    
    def convert_mp3(input_filepath:str, output_filepath:str):
      #FFmpeg command to convert the input MP3 file
      ffmpeg_cmd = [
        'ffmpeg',
        '-i', input_filepath,
        '-ar', '48000',  # Set the sample rate to 48000Hz
        '-b:a', '320k',  # Set the audio bitrate to 320kbps
        '-vn',  # Disable video stream
        '-codec:a', 'libmp3lame',  # Use LAME MP3 codec
        '-f', 'mp3',  # Specify the output file format as MP3
        output_filepath
      ]
      subprocess.run(ffmpeg_cmd, check=True)
    

    通过将ffmpeg/bin文件夹的路径添加到环境变量中,确保“ffmpeg”是可识别的命令。

    推荐文章