http://otnth.blogspot.com/2012/08/wmv2mkv.html
[original post]
mkvmerge 是不行的,因为某些恶心巴巴的协议问题。
ffmpeg也是不行的,会丢时间戳,虽然remux出来是可以正常拖动的,音画也是同步的,但是拖动非常慢,和原本的wmv一样慢。
唯有gabest的mkv muxer,一个dshow滤镜,mux出来是完全妥的,拖动也十分流畅,但是因为这货是dshow滤镜,所以只能在graphedt或者graphstudio里面手动去连接,每个文件都要做一次打开文件->删掉默认解码滤镜和输出滤镜->添加mkv muxer->添加file writer并指定输出文件名->连接源文件muxer和writer这一大堆的步骤,一两个文件也就算了,几十个文件杀了我算了。
所以写了一个python脚本,把脚本所在文件夹以及子文件夹里面的wmv都转为mkv,另外还需要psutil以及特殊版本的graphstudio(http://blog.thecybershadow.net/2010/06/07/graphstudio-fork/)。
这个graphstudio fork呢虽说支持xml更好了也支持命令行传递过去后台执行,但是有个很严重的问题就是一旦用了/render大法,子进程render完毕后是不会退出的,也不会释放输出文件句柄,所以判断是否mux完毕了确实让我头疼了一会儿。
import os,subprocess,psutil,time
xml="""<?xml version="1.0" encoding="utf-8"?>
<graph name="Unnamed Graph">
<filter name="File Sink" clsid="{8596E5F0-0DA5-11D0-BD21-00A0C911CE86}">
<ifilesinkfilter dest="%(dest)s"/>
</filter>
<filter name="Matroska Muxer" clsid="{1E1299A2-9D42-4F12-8791-D79E376F4143}"/>
<filter name="%(src)s" clsid="{187463A0-5BB7-11D3-ACBE-0080C75E246E}">
<ifilesourcefilter source="%(src)s"/>
</filter>
<connect outfilter="Matroska Muxer" outpin="0" infilter="File Sink" inpin="0" direct="true"/>
<connect outfilter="%(src)s" outpin="0" infilter="Matroska Muxer" inpin="0" direct="true"/>
<connect outfilter="%(src)s" outpin="1" infilter="Matroska Muxer" inpin="1" direct="true"/>
<command msg="run"/>
</graph>"""
startupinfo=subprocess.STARTUPINFO()
startupinfo.dwFlags|=subprocess._subprocess.STARTF_USESHOWWINDOW
def convert():
tmp=os.path.join(os.path.dirname(os.path.realpath(__file__)),'tmp.xml')
for root,dirs,files in os.walk(os.path.dirname(os.path.realpath(__file__))):
for f in files:
if f.endswith('.wmv'):
fullname=os.path.join(root,f)
mkv=fullname[:-4]+'.mkv'
if not os.path.exists(mkv):
try:
with open(tmp,'w') as file:
file.write(xml%{'src':fullname,'dest':mkv})
popen=subprocess.Popen([r"c:\Program Files\1exe\graphstudio.exe",'/render',tmp],startupinfo=startupinfo)
ps=psutil.Process(popen.pid)
orisize=os.path.getsize(fullname)
print('parsing',f,'...',end='')
while True:
p=ps.get_cpu_percent(interval=1)
# print(p)
if p<0.1:
writesize=ps.get_io_counters().write_bytes
if abs(orisize-writesize)>5*10**6:
continue
popen.kill()
break
time.sleep(0.1)
print('... done')
except subprocess.CalledProcessError as e:
print(f,'is fucked')
return
if os.path.exists(tmp):
os.remove(tmp)
convert()
另外,由于编码问题,貌似需要py3k再另外,blogger的html编辑器乱加tag很烦人
再再另外,blogger现在打横幅说Your browser is no longer supported by Blogger. 我只想对google说:你妈逼
没有评论:
发表评论