基于FFmpeg利用Python脚本转换视频为分片文件以及截图

import os
import sys
from xpinyin import Pinyin
#接受外部传入的视频存放路径
path = sys.argv[1] 
p = Pinyin()
for root,dirs,files in os.walk(path):
    for file in files:
        file_all_name = os.path.basename(file)
        file_name = file_all_name.split('.')[0]
        print("文件全名:"+file_all_name)
        #获取姓名全拼音
        name_py = p.get_pinyin(file_name,'')
        print("文件名:"+file_name)
        print("路径名:"+root)
        #为每一个视频创建一个文件夹存放视频分片
        new_dir_path = root+'\\'+name_py
        #文件夹不存在则创建
        if not os.path.exists(new_dir_path):
            os.makedirs(new_dir_path)
        new_path = new_dir_path +"\\"+ name_py
        #获取截图
        pic_path_name = root+'\\'+name_py +".jpg"
        if not os.path.exists(pic_path_name):
            #获取截图
            order = "ffmpeg -i  "+os.path.join(root,file)+"  -r 1 -q:v 2 -f image2 -t 1 "+pic_path_name
            os.system(order)
        #获取视频分片
        print("ffmpeg -i "+os.path.join(root,file)+" -hls_time 10 -hls_list_size 0 -hls_segment_filename "+new_path+"-%05d.ts "+new_path+".m3u8")
        order = "ffmpeg -i "+os.path.join(root,file)+" -hls_time 10 -hls_list_size 0 -hls_segment_filename "+new_path+"-%05d.ts "+new_path+".m3u8"
        os.system(order)

你可能感兴趣的:(基于FFmpeg利用Python脚本转换视频为分片文件以及截图)