python视频格式转换_将ppt文件转成mp4视频的Python脚本
ppt2mp4 (Python2.7)
将ppt文件转成mp4视频。GitHub
前提
1.需要Windows系统,并且启用了Windows多媒体播放器。需要安装Office 2010已上版本。因为PowerPoint把ppt转成视频需要依赖Windows多媒体播放器,如果没启用的话需要从设置里启用桌面体验功能。启用步骤可以参考:https://www.omnivex.com/suppo...
使用
1.安装Office 2010或更高版本
2.启用桌面体验功能(如果没启用的话)。
3.编辑convert.py,修改ppt_path,mp4_path路径,然后运行python convert.py。
# -*- coding: UTF-8 -*-
import win32com.client
import time
import os
import shutil
def ppt_to_mp4(ppt_path,mp4_target,resolution = 720,frames = 24,quality = 60,timeout = 120):
# status:Convert result. 0:failed. -1: timeout. 1:success.
status = 0
if ppt_path == '' or mp4_target == '':
return status
# start_tm:Start time
start_tm = time.time()
# Create a folder that does not exist.
sdir = mp4_target[:mp4_target.rfind('\\')]
if not os.path.exists(sdir):
os.makedirs(sdir)
# Start converting
ppt = win32com.client.Dispatch('PowerPoint.Application')
presentation = ppt.Presentations.Open(ppt_path,WithWindow=False)
# CreateVideo() function usage: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.createvideo
presentation.CreateVideo(mp4_target,-1,1,resolution,frames,quality)
while True:
try:
time.sleep(0.1)
if time.time() - start_tm > timeout:
# Converting time out. Killing the PowerPoint process(An exception will be threw out).
os.system("taskkill /f /im POWERPNT.EXE")
status = -1
break
if os.path.exists(mp4_path) and os.path.getsize(mp4_target) == 0:
# The filesize is 0 bytes when convert do not complete.
continue
status = 1
break
except Exception, e:
print 'Error! Code: {c}, Message, {m}'.format(c = type(e).__name__, m = str(e))
break
print time.time()-start_tm
if status != -1:
ppt.Quit()
return status
if __name__ == '__main__':
# Require Windows system(Media Player was enabled) and Microsoft Office 2010 or higher.
# Converting ppt into video relies on Windows Media Player. So you need to enable Desktop Experience feature.
# More save types please visit: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.ppsaveasfiletype
# quality:0-100. The level of quality of the slide. The higher the number, the higher the quality.
quality = 60
# resolution:The resolution of the slide. 480,720,1080...
resolution = 720
# frames: The number of frames per second.
frames = 24
# ppt_path:The ppt/pptx/pptm file path.
ppt_path = os.path.abspath('./test.pptx')
# mp4_path:The mp4 video save path.
mp4_path = os.path.abspath('./test.mp4')
# ie_temp_dir:The convert cache file path.
# The default path (hidden) is 'C:/Users/username/AppData/Local/Microsoft/Windows/Temporary Internet Files/Content.MSO/ppt'.
# Or 'C:/Users/username/AppData/Local/Microsoft/Windows/INetCache/Content.MSO/ppt'
# You can find the cache folde at IE setting.
# If you don't want clear cache files,assign ie_temp_dir with empty string.
#ie_temp_dir = 'C:/Users/username/AppData/Local/Microsoft/Windows/INetCache/Content.MSO/ppt'
ie_temp_dir = ''
# status:Converting result. 0:failed. -1: timeout. 1:success.
status = 0
# timeout: Seconds that converting time out.
timeout = 4*60
try:
status = ppt_to_mp4(ppt_path,mp4_path,resolution,frames,quality,timeout)
# Clear PowerPoint cache after convert completed. When you converted hundreds of files, the cache folder will be huge.
if ie_temp_dir != '':
shutil.rmtree(ie_temp_dir, ignore_errors=True)
except Exception, e:
print 'Error! Code: {c}, Message, {m}'.format(c = type(e).__name__, m = str(e))
if status == -1:
print 'Failed:timeout.'
elif status == 1:
print 'Success!'
else:
if os.path.exists(mp4_path):
os.remove(mp4_path)
print 'Failed:The ppt may have unknow elements. You can try to convert it manual.'
python视频格式转换_将ppt文件转成mp4视频的Python脚本相关推荐
- macbook视频格式转换_Mac App Store 上的“一键视频格式转换器”
一键视频转换器 - 快速.简单.免费的视频转换器. 这个免费视频转换器软件可以转换几乎所有的视频/音频文件格式,如MTS,M2TS,TS,TRP,MP4,MOV,M4V,MKV,AVI,WMV,FLV ...
- 批量 m3u8文件转成MP4的方法--Python实现和 cmd 实现(推荐cmd)--仅粉丝可见
# 批量 m3u8文件转成MP4的方法 但是因为os.listdir()顺序的问题,此方法可能会导致乱序,所以推荐另外一种. cmd部分引用链接:https://jingyan.baidu.com/ ...
- macbook视频格式转换_一键视频格式转换器for Mac-一键视频格式转换器Mac版下载 V6.3.37-PC6苹果网...
一键视频格式转换器Mac版是Mac电脑上的一款最好用的视频格式转换器之一.一键视频格式转换器Mac版是一款快速.简单.免费的视频转换器. 软件特色 一键视频格式转换器Mac版作为一款免费视频转换器软件 ...
- macbook视频格式转换_为了找到MacBook这个视频转换软件我哭了!太强大了!
Mac自带的quicktime录制的默认格式为mov,这个格式实在是不好放到手机上播放.还有一些其他的视频格式,也是无法在iPhone上面进行播放的,因此急迫需要一款格式转换工具.而Total Vid ...
- html的视频格式转换,盘点10个免费实用的 HTML 视频转换工具
现在,人们都喜欢看视频目前,大多数的人都是看视频在线或移动.因此,视频必须有正确的格式,可以通过手机或支持系统.因此,人们需要一些应用程序的工具,将有助于他们现有的文件格式转换成当前的格式如MP4,W ...
- python datetime格式转换_分别用Excel和python进行日期格式转换成时间戳格式
最近在处理一份驾驶行为方面的数据,其中要用到时间戳,因此就在此与大家一同分享学习一下. 1.什么是时间戳? 时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01 ...
- macbook视频格式转换_告别格式工厂的视频格式转换方法(mac版 命令行)
macbook pro 安装ffmpeg 及 简单使用 说明 在B站上看到一个关于ffmpeg转换视频文件的视频, 虽然里面很详细, 但只有windows版本的安装及使用, 于是想在mac系统下安装 ...
- python实现坐标系转换_(数据科学学习手札60)用Python实现WGS84、火星坐标系、百度坐标系、web墨卡托四种坐标相互转换...
importmathclassLngLatTransfer():def __init__(self): self.x_pi= 3.14159265358979324 * 3000.0 / 180.0s ...
- Movavi HD Video Converter for Mac (优秀的视频格式转换工具) v22.1
今天和大家分享 Movavi HD Video Converter for Mac 中文版本,这是一款Mac上强大易用的视频格式转换工具,支持几乎所有常见的视频格式,提供大量针对不同设备的预设,简单易 ...
最新文章
- 重磅直播|大规模点云可视化技术
- Oracle Dataguard中备库中归档日志不同步
- C1000k 新思路:用户态 TCP/IP 协议栈
- [转]删除MSSQL所有的约束及表格
- php ar 模式,AR技术也被称为什么技术
- Redis与RabbitMQ作为消息队列的比较
- 方法 手写promise_JS探索-手写Promise
- 数据结构之malloc()函数动态内存分配复习
- 插件拓展 - 利用js实现n个元素重新组合
- python怎样保存在桌面_python3应用windows api对后台程序窗口及桌面截图并保存的方法...
- 天天学算法——搜索热词关联(TopK)
- 使用paython制作简单贺卡
- OSChina 周一乱弹 —— 带你装逼带你飞~
- java开发有必要刷leetcode吗_刷 leetcode 需要哪些基础?
- Android SMB 简单几步实现手机给电脑传输数据
- winpe装双系统linux_LINUX下安装WINDOWS双系统
- HashMap源码探究
- python爬虫从企查查获取企业信息-手工绕开企查查的登录验证
- Jetpack Compose Animations 超简单教程
- Android github上优秀开源项目分类汇总