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

  • 相关阅读:
    F#周报2019年第33期
    The .NET World——gPRC概览
    编程杂谈——Non-breaking space
    F#周报2019年第32期
    F#周报2019年第31期
    F#周报2019年第30期
    pat 乙级 1015. 德才论 (25) c++
    pat 乙级 1008. 数组元素循环右移问题 (20)
    PAT 乙级 1007. 素数对猜想 (20) c++ 筛选法求素数
    PAT-B 1005. 继续(3n+1)猜想 (25) c++
  • 原文地址:https://www.cnblogs.com/chargeworld/p/12372127.html
Copyright © 2011-2022 走看看