最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python如何將aac轉(zhuǎn)為mp3,保持原有目錄結(jié)構(gòu)

 更新時(shí)間:2024年11月07日 09:29:42   作者:nongcunqq  
使用Python腳本實(shí)現(xiàn)AAC格式轉(zhuǎn)MP3格式的方法介紹,需要用戶輸入AAC文件所在目錄路徑和MP3輸出目錄路徑,通過調(diào)用FFmpeg工具實(shí)現(xiàn)格式轉(zhuǎn)換,該腳本簡單易懂,適合需要批量處理音頻文件的用戶,使用前需確保已安裝FFmpeg環(huán)境

將aac轉(zhuǎn)為mp3,保持原有目錄結(jié)構(gòu)

需要提前安裝FFmpeg

import os
import subprocess
import time
from concurrent.futures import ThreadPoolExecutor, as_completed

def convert_file(input_path, output_path):
    command = [
        'ffmpeg',
        '-y',  # 自動(dòng)覆蓋現(xiàn)有文件
        '-i', input_path,
        '-acodec', 'libmp3lame',
        '-b:a', '192k',
        output_path
    ]
    try:
        subprocess.run(command, check=True, stderr=subprocess.PIPE, timeout=300)  # 5分鐘超時(shí)
        return f"Converted: {output_path}"
    except subprocess.CalledProcessError as e:
        return f"Error converting {input_path}: {e.stderr.decode()}"
    except subprocess.TimeoutExpired:
        return f"Timeout converting {input_path}"

def convert_aac_to_mp3(input_dir, output_dir):
    start_time = time.time()
    total_files = 0
    processed_files = 0
    converted_files = 0

    with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
        futures = []

        for root, _, files in os.walk(input_dir):
            for filename in files:
                if filename.lower().endswith('.aac'):
                    total_files += 1
                    input_path = os.path.join(root, filename)
                    rel_path = os.path.relpath(root, input_dir)
                    output_filename = os.path.splitext(filename)[0] + '.mp3'
                    output_path = os.path.join(output_dir, rel_path, output_filename)
                    
                    os.makedirs(os.path.dirname(output_path), exist_ok=True)
                    
                    futures.append(executor.submit(convert_file, input_path, output_path))

        for future in as_completed(futures):
            result = future.result()
            print(result)
            processed_files += 1
            if "Converted" in result:
                converted_files += 1
            print(f"Progress: {processed_files}/{total_files} files processed")

    end_time = time.time()
    print(f"\nConversion completed.")
    print(f"Total files: {total_files}")
    print(f"Converted files: {converted_files}")
    print(f"Failed conversions: {total_files - converted_files}")
    print(f"Total time: {end_time - start_time:.2f} seconds")

使用腳本

input_dir = input("請(qǐng)輸入包含 AAC 文件的目錄路徑: ")
output_dir = input("請(qǐng)輸入 MP3 文件的輸出目錄路徑: ")
convert_aac_to_mp3(input_dir, output_dir)

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python制作進(jìn)度條的四種方法總結(jié)

    Python制作進(jìn)度條的四種方法總結(jié)

    如果你之前沒用過進(jìn)度條,八成是覺得它會(huì)增加不必要的復(fù)雜性或者很難維護(hù),其實(shí)不然。要加一個(gè)進(jìn)度條其實(shí)只需要幾行代碼,快跟隨小編一起學(xué)習(xí)學(xué)習(xí)吧
    2022-11-11
  • 解決import tensorflow as tf 出錯(cuò)的原因

    解決import tensorflow as tf 出錯(cuò)的原因

    這篇文章主要介紹了解決import tensorflow as tf 出錯(cuò)的原因,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • python用tkinter實(shí)現(xiàn)一個(gè)簡易能進(jìn)行隨機(jī)點(diǎn)名的界面

    python用tkinter實(shí)現(xiàn)一個(gè)簡易能進(jìn)行隨機(jī)點(diǎn)名的界面

    這篇文章主要介紹了python用tkinter實(shí)現(xiàn)一個(gè)簡易能進(jìn)行隨機(jī)點(diǎn)名的界面,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • linux 下實(shí)現(xiàn)python多版本安裝實(shí)踐

    linux 下實(shí)現(xiàn)python多版本安裝實(shí)踐

    這篇文章主要介紹了linux 下實(shí)現(xiàn)python多版本安裝實(shí)踐,需要的朋友可以參考下
    2014-11-11
  • python3 os進(jìn)行嵌套操作的實(shí)例講解

    python3 os進(jìn)行嵌套操作的實(shí)例講解

    在本篇文章里小編給大家整理了關(guān)于python3 os進(jìn)行嵌套操作的實(shí)例內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。
    2020-11-11
  • python 如何引入?yún)f(xié)程和原理分析

    python 如何引入?yún)f(xié)程和原理分析

    這篇文章主要介紹了python 如何引入?yún)f(xié)程和原理分析,幫助大家更好得理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2020-11-11
  • Python?數(shù)據(jù)可視化超詳細(xì)講解折線圖的實(shí)現(xiàn)

    Python?數(shù)據(jù)可視化超詳細(xì)講解折線圖的實(shí)現(xiàn)

    數(shù)據(jù)可以幫助我們描述這個(gè)世界、闡釋自己的想法和展示自己的成果,但如果只有單調(diào)乏味的文本和數(shù)字,我們卻往往能難抓住觀眾的眼球。而很多時(shí)候,一張漂亮的可視化圖表就足以勝過千言萬語,讓我們來用Python實(shí)現(xiàn)一個(gè)可視化的折線圖
    2022-03-03
  • python3 QT5 端口轉(zhuǎn)發(fā)工具兩種場(chǎng)景分析

    python3 QT5 端口轉(zhuǎn)發(fā)工具兩種場(chǎng)景分析

    這篇文章主要介紹了python3 QT5 端口轉(zhuǎn)發(fā)工具,功能是打開本機(jī)端口,映射到指定IP的端口,接下來通過兩種場(chǎng)景給大家詳細(xì)介紹,感興趣的朋友一起看看吧
    2022-01-01
  • Python利用Selenium實(shí)現(xiàn)簡單的中英互譯功能

    Python利用Selenium實(shí)現(xiàn)簡單的中英互譯功能

    Selenium 是一個(gè)用于 Web 應(yīng)用程序測(cè)試的工具,最初是為網(wǎng)站自動(dòng)化測(cè)試而開發(fā)的,可以直接運(yùn)行在瀏覽器上,是 Python 的一個(gè)第三方庫,對(duì)外提供的接口能夠操作瀏覽器,從而讓瀏覽器完成自動(dòng)化的操作,本文介紹了如何利用Python中的Selenium實(shí)現(xiàn)簡單的中英互譯
    2024-08-08
  • python selenium xpath定位操作

    python selenium xpath定位操作

    這篇文章主要介紹了python selenium xpath定位操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09

最新評(píng)論

新营市| 洪雅县| 怀仁县| 韶山市| 墨玉县| 滁州市| 札达县| 黑龙江省| 青铜峡市| 古丈县| 平泉县| 上栗县| 湄潭县| 上饶县| 定陶县| 大英县| 华阴市| 南木林县| 柘城县| 炉霍县| 永年县| 社会| 光泽县| 潜山县| 敖汉旗| 治多县| 当阳市| 锡林浩特市| 民和| 东源县| 礼泉县| 海丰县| 满城县| 车致| 桑日县| 西峡县| 榆中县| 栾川县| 同心县| 杨浦区| 嘉祥县|