最近項目需要,想做個對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,運行成功。
先記錄這些。