最近项目需要,想做个对mp4文件进行解析的工具。
虽然已经有很多开源/收费的分析工具,如eseye等,但还是想做个自己的;一方面学习学习python,使用python写该工具(貌似没看到有python做的),另一方面,也是方便定制维护,要自己想要的功能,测试不太需要的就不做进去了。
自己是个python菜鸟,对这个工具仅有个基本的思路:
1、可分析mp4文件,具体包括分辨率、帧率、码率、码率类型、I帧间隔、时间戳等。
2、python代码编写,有GUI,可以弹窗选mp4文件。
3、文本输出mp4文件分析情况、单帧分析情况等。
暂时考虑到的大的方面仅这些吧。
简单了解了一下,整个mp4文件分析还是要花较大精力和时间的,现在还在一边看mp4文件格式,另一方面考虑可不可以借助已有的分析库。
了解的不多,这个边看边学习考虑吧。先把基本环节配置起来。
1、python27,编译环境eclipse
2、GUI看了下,常用的有Tkinter,还有PyQt
就用PyQt试试
1、安装python27,比较简单,eclipse直接使用解压版的。
2、安装pyQt4,有exe文件,也比较简单。
3、看教程,写个简单的GUI,了解一下PyQt的方法
from:http://www.linuxidc.com/Linux/2012-06/63652p2.htm
实现代码如下:
- # -*- coding: utf-8 -*-
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- import sys
- QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
- class StandardDialog(QDialog):
- def __init__(self,parent=None):
- super(StandardDialog,self).__init__(parent)
- self.setWindowTitle("Standard Dialog")
- filePushButton=QPushButton(self.tr("文件对话框"))
- colorPushButton=QPushButton(self.tr("颜色对话框"))
- fontPushButton=QPushButton(self.tr("字体对话框"))
- self.fileLineEdit=QLineEdit()
- self.colorFrame=QFrame()
- self.colorFrame.setFrameShape(QFrame.Box)
- self.colorFrame.setAutoFillBackground(True)
- self.fontLineEdit=QLineEdit("Hello World!")
- layout=QGridLayout()
- layout.addWidget(filePushButton,0,0)
- layout.addWidget(self.fileLineEdit,0,1)
- layout.addWidget(colorPushButton,1,0)
- layout.addWidget(self.colorFrame,1,1)
- layout.addWidget(fontPushButton,2,0)
- layout.addWidget(self.fontLineEdit,2,1)
- self.setLayout(layout)
- self.connect(filePushButton,SIGNAL("clicked()"),self.openFile)
- self.connect(colorPushButton,SIGNAL("clicked()"),self.openColor)
- self.connect(fontPushButton,SIGNAL("clicked()"),self.openFont)
- def openFile(self):
- s=QFileDialog.getOpenFileName(self,"Open file dialog","/","Python files(*.py)")
- self.fileLineEdit.setText(str(s))
- def openColor(self):
- c=QColorDialog.getColor(Qt.blue)
- if c.isValid():
- self.colorFrame.setPalette(QPalette(c))
- def openFont(self):
- f,ok=QFontDialog.getFont()
- if ok:
- self.fontLineEdit.setFont(f)
- app=QApplication(sys.argv)
- form=StandardDialog()
- form.show()
- app.exec_()
运行成功,没什么问题
4、GUI生成exe
上述代码可以运行成功,但是如何生成exe文件呢。
百度了一下,常用py2exe和pyinstaller。
py2exe安装了一下,生成后无法运行,提示需要安装sip,安装sip时,需要minGW,放弃之。。
pyinstaller安装比较简单,需要安装pywin32,安装成功后,python pyinstaller.py -w pyQ.py,在生成的dist文件夹中找到pyQ.exe,运行成功。
先记录这些。
