老妈叫下广场舞视频,想用python转换下视频格式flv转换为mp4

 首先下载B站的广场舞视频

cmd 利用you-get直接下载 



# -*- coding:utf-8 -*-
# time: 2020/9/22--20:04
#__author__ = 'challen'
 
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 = '/C:/Users/NING MEI/Desktop'
    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(9999)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值