# !/usr/bin/python
# -*- coding:utf-8 -*-
# time: 2020/03/18--20:12
__author__ = 'wenguanjun'

import requests, time, urllib.request, re, os
from moviepy.editor import *
import os, sys, threading, json

import imageio

imageio.plugins.ffmpeg.download()


if __name__ == '__main__':
    start_time = time.time()
    video_path = '/Volumes/WS/temp'
    file_list = os.listdir(video_path)

    commands = []
    for f in file_list:
        fileDir = video_path + '/' + f
        if not os.path.isdir(fileDir):
            continue
        file_list_dir = os.listdir(fileDir)
        for file in file_list_dir:
            if str(file).__contains__('.DS_Store'):
                continue
            if not str(file).__contains__('.flv'):
                continue
            if str(file).__contains__('._'):
                continue
            file = file.replace('._','')
            filePath = fileDir + '/' + file
            file = file.replace(' ','-').replace('(','-').replace(')','-').replace('(','-').replace(")",'-')
            filePathNew = fileDir + '/' + file
            if filePath != filePathNew:
                try:
                    os.rename(filePath, filePathNew)
                except:
                    pass
            tsPath = fileDir + '/' + file.replace('.flv','.ts')
            mp4Path = fileDir + '/' + file.replace('.flv','.mp4')
            cmd_ts_command = 'ffmpeg -i ' + filePathNew + ' -c copy -bsf:v h264_mp4toannexb -f mpegts ' + tsPath
            cmd_mp4_command = 'ffmpeg -i "concat:' + tsPath + '" -c copy -bsf:a aac_adtstoasc -movflags +faststart ' + mp4Path
            if cmd_ts_command not in commands:
                commands.append(cmd_ts_command)
                print(cmd_ts_command)
                cmd_ts_command_out = os.popen(r"" + cmd_ts_command, "r")
                print(cmd_ts_command_out.read())
                time.sleep(10)
            if cmd_mp4_command not in commands:
                print(cmd_mp4_command)
                cmd_mp4_command_out = os.popen(r"" + cmd_mp4_command, "r")
                print(cmd_mp4_command_out.read())
                time.sleep(10)
            try:
                print('删除:'+tsPath)
                print('删除:'+filePathNew)
                os.remove(tsPath)
                os.remove(filePathNew)
            except:
                pass
    print('休息')
    time.sleep(10000)


 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐