rwv60O.png

# -*- coding: utf-8 -*-
#!/usr/local/bin/python


import os
import subprocess
import time
import logging


logger = logging.getLogger()
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
fh = logging.FileHandler(filename="./convert.log")
formatter = logging.Formatter(
    "%(asctime)s - %(name)s - line:%(lineno)d - %(levelname)s - %(message)s"
)
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(ch)  # 将日志输出至屏幕
logger.addHandler(fh)  # 将日志输出至文件

movie_path = r"e:\media"
movie_type = [".mkv", ".rmvb", ".avi",".flv",".MKV", ".RMVB", ".AVI",".FLV"]

for root, dir, files in os.walk(movie_path):
    for file in files:
        # print(file)
        shotname, extension = os.path.splitext(file)
        # print(shotname,extension)
        source_name = os.path.join(root, file)
        target_name = os.path.join(root, f"{shotname}.mp4")
        if extension in movie_type and not os.path.exists(target_name):
            logger.info(f"{source_name} -> {target_name}")
            bin_path = (
                r"D:\program\ffmpeg\bin\ffmpeg.exe"
            )
            #command = f"{bin_path} -i {source_name} -strict -2 {target_name}"
            command = f"{bin_path} -i {source_name} -c:v copy -c:a copy {target_name}"
            logger.info(command)
            try:
                a = subprocess.run(command, shell=True)
                if a.returncode == 0:
                    logger.info("convert successful.")
                    b = subprocess.run(f"del {source_name}", shell=True)
                    if b.returncode == 0:
                        logger.info("delete source successful.")
            except Exception as e:
                logger.info(f"conver error :{e}")

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code