zoukankan      html  css  js  c++  java
  • 视频格式转换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

  • 相关阅读:
    重建索引报错-python数据分析
    机器学习实战1-2.1 KNN改进约会网站的配对效果 datingTestSet2.txt 下载方法
    机器学习实战1-1 KNN电影分类遇到的问题
    权限掩码umask详解
    spark配置(7)--on yarn配置
    spark配置(6)-独立应用程序
    spark配置(5)-独立应用程序
    spark配置(4)-----Spark Streaming
    spark配置(3)
    spark配置(2)
  • 原文地址:https://www.cnblogs.com/chargeworld/p/12372127.html
Copyright © 2011-2022 走看看