• 视频格式转换mp4


    第一步:https://ffmpeg.zeranoe.com/builds/下载ffmpeg 

    或者:百度云下载:

    链接:https://pan.baidu.com/s/1x_QogbV8xFjkYTeDpB1LVA
    提取码:w04r 

    第二部:解压并复制改目录的ffmpeg.exe文件路径

    # -*- coding: utf-8 -*-
    #!/usr/local/bin/python
    # Time: 2017/8/30 22:17:47
    # Description:
    # File Name: movie2mp4.py
    
    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"C:UsersuserDesktopchaos"
    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"c:UsersuserDesktopffmpeg-20200225-36451f9-win64-staticffmpeg-20200225-36451f9-win64-staticinffmpeg.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}")
    

      

    第三步:python打开改代码并把需要替换视频的储存的路径替换move_path

    第二步复制的ffmpeg.exe的路径替换bin_path

    第四步:执行代码

    ok

  • 相关阅读:
    C
    A
    hdu 三部曲1 Popular Cows tarjan算法&&缩点&&拓扑排序
    hdu 三部曲 Going Home 最小费用最大流 EK算法
    hdu 三部曲 1Minimum Cost 最小费用最大流EK算法
    hdu 三部曲1 Is the Information Reliable? 差分约束 bellman_ford算法
    hdu 三部曲1 Intervals 差分约束问题 spfa算法
    hdu 三部曲 Crashing Robots
    hdu 三部曲2 Rebuilding Roads
    Codeforces 1277C As Simple as One and Two
  • 原文地址:https://www.cnblogs.com/chargeworld/p/12372127.html
Copyright © 2020-2023  润新知